JS DOM: appendChild
target_node.appendChild(new_node)
- Append new_node as child of target_node
- Return the appended new_node.
🛑 warning: If the node to be inserted already exists in the same doc, it is removed from the original place and moved to the new place.
// get first paragraph const xx = document.getElementsByTagName("p")[0]; // move it to bottom of body document.body.appendChild(xx);
Copy and Append Node
To stop it from moving, you can make a clone first.
// get first paragraph const xx = document.getElementsByTagName("p")[0]; // clone and add it to bottom of body document.body. appendChild(xx.cloneNode(true));