I want change image url dynamically based id attribute using jquery below i given the svg tag. any one help me.
<image id="background_image" width="804" height="943" preserveAspectRatio="xMinYMin" style=" pointer-events:none;background-repeat:repeat-y;" xlink:href="http://www.example.com/img/imag.png">
i want change dynamically the blow url http://www.example.com/img/imag.png
一个具有attr
的简单选择器(如下面的选择器)应该适合您。
$('#background_image').attr('xlink:href','newurl.com/image.png');
Use the jQuery .attr()
to update the href
.
$(function() { $('#background_image').attr('xlink:href', 'http://placehold.it/350x150'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <image id="background_image" width="804" height="943" preserveAspectRatio="xMinYMin" style=" pointer-events:none;background-repeat:repeat-y;" xlink:href="http://www.example.com/img/imag.png">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.