JS: appendChild (Append Element as Child)

By Xah Lee. Date: . Last updated: .

node.appendChild(newNode)

// 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));