javascript - change the xlink:href of an <image> in a svg, through a classic <a> link -


i have svg in webpage (i use php):

<svg width="500px" height="500px" xml:lang="fr" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <image width="500" height="500" xlink:href="img1.jpg" opacity="0.35" /> </svg> 

i able change xlink:href variable when clicking on link (and without reload webpage), like:

<a href=#" onclick="changexlinkhref(img2.jpg)">change img2</a> 

but don't know code of js function changexlinkhref(img){} (and don't use jquery on project)

thanks!

you'll need put img2.jpg argument in single quotes should provided have 1 image element on page.

function changexlinkhref(value) {   document.queryselector("image").setattributens('http://www.w3.org/1999/xlink', 'xlink:href', value); } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -