Student-friendly HTML, CSS, and JavaScript reference with examples
Adds an element as a child of another element.
const parent = document.querySelector('.container');
const newDiv = document.createElement('div');
newDiv.textContent = 'I am new!';
parent.appendChild(newDiv);
The new element appears at the end of the parent’s children.