Tag Archives: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’

[Solved] DOM Add Element to HTML Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’

DOM adds element failed to execute ‘appendChild’ on ‘node’ to HTML: parameter 1 is not of type ‘node’ problem

Problem: failed to execute ‘appendChild’ on ‘node’: parameter 1 is not of type ‘node’

Cause: the parameter of appendChild is a node node, which leads to such a problem. It indicates that the current parameter is not a node, but may be a string.

For example:

In this case, DOM is a string

Solution:

var dom=document.createElement('p');
dom.className='book';
dom.innerHTML='hello world';
document.body.appendChild(dom);

At this point, the DOM is node.

If the added element is a string, create a node using document. Createtextnode().

var dom=document.createTextNode('hello world');

Effect in HTML: