Setting the href attribute of an SVG link

I have been working on a project that required a fairly interactive SVG recently and ran into a small snag with links. To set an attribute of an SVG element you would normally do something like this:

el.setAttributeNS(null, "visibility", 'visibile');

This doesn’t work with links because the href attribute is namespaced with xlink (It looks like this is being removed in SVG 2). So you would embed a link in a page like this:

<a xlink:href="/about" id="InfoLink" target="_top">..wrapped nodes..</a>

And set the href attribute like this:

el.setAttributeNS( "http://www.w3.org/1999/xlink", "href", "/otherpage");

18. August 2011 by admin
Categories: Development | Tags: , | Leave a comment

Leave a Reply

Required fields are marked *

*