javascriptjqueryjquery-svg

How to change the image url in svg using jquery?


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


Solution

  • A simple selector with attr like the one below should work for you.

    $('#background_image').attr('xlink:href','newurl.com/image.png');