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.