Skip to main content Accessibility Feedback

DOM Injection

Element.appendChild()

Insert an element at the end of a set of elements inside a shared parent. Call the appendChild() method on the reference node, and pass in the new node as an argument.

// Create a new element
var newNode = document.createElement('div');

// Get the reference node
var referenceNode = document.querySelector('#some-element');

// Insert the new node after the last element in the parent node
referenceNode.appendChild(newNode);

Works back to at least IE6.