appendChild()
The DOM method that inserts a node as the last child of an element, moving it if it was already somewhere else.
In more detail
Each appendChild on a live page can trigger style and layout work, so adding hundreds of items one by one is slow. Build them in a DocumentFragment and append the fragment once instead.
Related terms
- DocumentFragment — A lightweight container for DOM nodes that is not part of the page, used to build many nodes and insert them all in one step.
- document.createElement() — The DOM method that creates a new, detached element with a given tag name, ready to be filled in and inserted into the page.
- layout — The rendering stage in which the browser calculates the exact position and size of every box on the page.
Taught in
- HTML Parsing, Tokenization And The Document Object Model (DOM) — Frontend Architecture & Web Platform
- DOM Manipulation: DocumentFragment And HTML Templates — Frontend Architecture & Web Platform
- MutationObserver: Reactive DOM Watching Without Polling — Frontend Architecture & Web Platform