In the following example, I am trying to dynamically add a link tag to an svg element.
http://lizziemalcolm.com/svgtest.html
$('#button').click(function(){ $('.svgClass').wrap('<a xlink:href="http://www.w3.org/" />'); });
In the example, although the syntax is exactly the same, the ellipse with the dynamically added link disappears.
Any ideas why this could be happening?
The reason I'm trying to do this is because I want to create custom http://www.addthis.com/ icons using SVG, and the element should be enclosed in a tag.
Also tried with pure javascript, but no luck:
function wrapElem( innerId, wrapType, wrapperId, wrapperUrl ){ var innerElem = document.getElementById( innerId ), wrapper = document.createElement( wrapType ); wrapper.appendChild( innerElem.parentNode.replaceChild( wrapper, innerElem ) ); wrapper.setAttribute('xml:id', wrapperId); wrapper.setAttribute('xlink:href', wrapperUrl); return wrapper; }
Link
also updated
source share