parent.appendChild(child) adds a node to the end of the parent’s child list(MDN). If child already exists in the document, it is moved — not copied.
Status: Baseline Widely available (since July 2015) — not Deprecated, Experimental, or Non-standard. Prefer Element.append() when you need multiple args or text strings.
Remember
parent.appendChild(child)
→ child becomes the last child of parent
→ returns child (not parent)
If child already in the document → moved here
Need a copy? → cloneNode() first
Chaining nests:
parent.appendChild(a).appendChild(b)
→ b is inside a (returns the child each time)
Create (or select) a node, then append it to a parent.
Get a parent node (often an element).
Create or find the child (createElement, existing node, …).
Call parent.appendChild(child).
Use the return value if you need the child reference.
Piece
Required?
Role
parent
Yes
Node that receives the child
child
Yes
Node to append (or a DocumentFragment)
Return
—
The appended child (empty fragment if fragment)
Pseudocode
Pseudocode
child = createElement("p") // or an existing node
parent.appendChild(child)
→ child is last among parent.childNodes
if child already has a parent:
remove from old place, then insert at end of parent
copy needed?
parent.appendChild(child.cloneNode(true))
Reference
Cheat Sheet
Keep these facts handy when building DOM trees.
Topic
Detail
Syntax
parent.appendChild(child)
Returns
Appended child (or empty fragment)
Existing node
Moved, not cloned
Chaining
Nests — returns child each time
vs append()
Single Node arg vs multi + strings
Errors
HierarchyRequestError if tree rules break
Standard
Baseline Widely available (since July 2015)
Try it
Live Preview
Append a new item, move an existing item, or append a clone into the list.
List
Existing item
Browser demo of Node.appendChild() — move vs clone.
Result
Choose an action, then Run…
Code
JavaScript Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Append a New Element
Create a paragraph and append it to the body (MDN-style).
JavaScript
const p = document.createElement("p");
p.textContent = "Hello";
document.getElementById("box").appendChild(p);
Append in one expression. Create + append together.
Capture the return. Same node you appended.
Edit after append. Set textContent on that reference.
Not the parent. Do not expect a fluent “parent chain.”
Example 3 — Moving an Existing Node
Appending a node that is already in the tree moves it (MDN).
JavaScript
const list = document.getElementById("list");
const first = list.firstElementChild;
list.appendChild(first);
// first was removed from the start and added at the end
Clones are not live-synced with the original (MDN).
Edge Cases & Pitfalls
Check these before building complex trees with appendChild.
move
Existing nodes are moved
MDN: a node cannot be in two places. Append moves it unless you cloneNode.
return
Returns the child, not the parent
Chaining nests elements. Call appendChild separately on the parent for siblings.
hierarchy
HierarchyRequestError
Thrown for illegal trees (e.g. appending a node into its own descendant).
append
Element.append() for multi-args
MDN: prefer append() when you need multiple nodes or strings on an Element.
Compatibility
Browser Support
Node.appendChild() is marked Baseline Widely available on MDN (since July 2015).
✓ Baseline · Widely available
Node.appendChild()
Adds a child to the end of a parent. Moves existing nodes. Returns the appended child. Prefer Element.append() for multiple arguments or strings.
100%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
appendChild()Excellent
Bottom line: Safe everyday DOM API. Remember: move vs clone, and chaining nests. See the MDN appendChild reference.
Analysis
Performance Notes
Approach
Cost
Best for
One appendChild
One layout touch
Single node
Many appends in a loop
Can reflow often
Avoid for large lists
DocumentFragment then one append
One insert
Batch many children
For many nodes, build into a fragment (or use append with multiple args), then attach once — fewer layout thrashers than N separate appends.
Remember
Key Takeaways
Adds last: child becomes the end of parent’s children.
Moves: existing document nodes relocate, not copy.
Returns child: chaining nests — call on the parent for siblings.
Prefer append() for multiple nodes/strings on an Element.
One line:appendChild puts a node last under a parent — moving it if it already lived elsewhere.
Frequently Asked Questions
It adds the given child node to the end of the parent's list of children. If that child already exists elsewhere in the document, appendChild moves it — it does not clone it.
No. MDN marks Node.appendChild() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
It returns the appended child node. If you pass a DocumentFragment, it returns that fragment after its children have been moved (so the fragment is empty).
Because each call returns the child you just appended, not the parent. body.appendChild(p1).appendChild(p2) puts p2 inside p1, not as a sibling of p1.
Element.append() can take multiple nodes and text strings in one call. Prefer it when you are working with an Element and need those features. appendChild still works on any Node parent and remains the classic single-node API.
Call node.cloneNode(true) (or false for a shallow copy), then appendChild the clone. Appending the original always moves it.