Web APIs

Node.appendChild()

Try the free JavaScript compiler

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

NameTypeDescription
childNodeNode 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);
JavaScript Reference