I wrote javascript which dynamically edits an svg element. I want to get the new string of the edited svg element but currently my code fails.
I found here the following code to get the string form of an HTML document.
var txt = document.documentElement.innerHTML;
I just want the innerHTML of the SVG element. I tried the following code but get an error message saying “undefined”.
var svgnode=document.getElementById("svgnode1");
alert(svgnode.innerHTML);
How do I do that. The error occurs on Google Chrome but I want a solution that works on any browser.
innerHTMLis defined for HTML documents but not for XML DOMs of other kinds.There is some mechanism planned for
innerHTMLlike facilities for SVG. http://www.w3.org/Graphics/SVG/WG/wiki/SVG_2_DOM#innerHTML_type_facilities:If what you need is a way to turn SVG, or any other XML DOM into a string of XML, see https://developer.mozilla.org/en/Parsing_and_serializing_XML
or see https://stackoverflow.com/a/4916895/20394 for the IE equivalent.