Tag Archives: DOM adds elements to HTML Error

[Solved] DOM adds elements to HTML Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of typ…

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

reason: the parameter of appendChild is node. This problem indicates that the current parameter is not node, it may be a string

For example:

DOM is a string

solution:

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

In this case, DOM is node

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

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