Failed to execute 'appendChild' on 'Node': Only one element on document allowed

In my case, the DOM was complaining because I was trying to add a child in the document itself:

document.appendChild(myElement);

I solved it by getting a reference to the body tag:

document.body.appendChild(logger);

There is a difference between the root node of a document and the document element. What you want is the <svg> document element, but .contentDocument gets you the root node.

The root node is one hierarchy level further up. This means, the <svg> document element resides inside the root node, and the root node may only have this one <svg> child element.

To get the document element, do this:

svgXtraDoc = d.contentDocument.documentElement;

Tags:

Javascript

Svg