Skip to content Skip to sidebar Skip to footer

How To Get A Working Dynamic Javascript Reference In An Svg

What I am trying to do is to set the Javascript script reference in an embedded SVG document dynamically from Javascript code within the HTML. I assumed it would be just as easy a

Solution 1:

SVG elements must be created in the svg namespace which is http://www.w3.org/2000/svg so instead of createElement you must use createElementNS similarly for the xlink attribute it must go in the xlink namespace so you need

  var newref = svgdoc.contentDocument.createElementNS('http://www.w3.org/2000/svg', 'script');
  newref.setAttribute("type", "text/javascript");
  newref.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "script.js");

Post a Comment for "How To Get A Working Dynamic Javascript Reference In An Svg"