Reputation: 175
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
Upvotes: 2
Views: 1531
Reputation: 9561
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">
Upvotes: 1
Reputation: 47804
A simple selector with attr
like the one below should work for you.
$('#background_image').attr('xlink:href','newurl.com/image.png');
Upvotes: 3