Is there some innerHTML replacement in SVG/XML?

You can use DOMParser to parse XML. You can then use importNode to get that into your existing document if you want via importNode to end up with something like this…

var doc = new DOMParser().parseFromString(
   '<svg xmlns="http://www.w3.org/2000/svg"><circle cx="100" cy="100" r="20"/></svg>',
   'application/xml');

someElement.appendChild(
 someElement.ownerDocument.importNode(doc.documentElement, true));

Leave a Comment