Categories
JavaScript Answers

How to fix Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’ with JavaScript?

Spread the love

To fix Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’ with JavaScript, we should make sure we call appendChild with a valid node.

For instance, we write

const z = document.createElement("p");
z.innerHTML = "hello";
document.body.appendChild(z);

to create a p element node with createElement.

And then we set its innerHTML property to 'hello'.

Finally, we call document.body.appendChild to append the z element as the last child of the body element.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *