Web APIs
Node.appendChild()
Append a node, moving it from its previous parent if necessary. Unlike append(), it accepts a single node and returns it. Example console output: true 0 1.
Formal Syntax & Structure
javascript syntaxjavascript
parent.appendChild(child)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| child | Node | Node to insert. |
Return Value
Node
The supplied node, including a fragment when supplied.
Working Example
Example Snippetjavascript
const a=document.createElement("div"),b=document.createElement("div"),p=document.createElement("p"); a.appendChild(p); console.log(b.appendChild(p)===p,a.children.length,b.children.length);