Web APIs

Element.append()

Try the free JavaScript compiler

append inserts nodes or strings after existing children. Inserting a node already in a tree moves it rather than duplicating it. cloneNode is needed for a separate copy.

Formal Syntax & Structure

javascript syntaxjavascript
element.append(...nodesOrStrings)

Parameters & Attributes

NameTypeDescription
nodesOrStringsNode | stringZero or more nodes or strings to insert.

Return Value

undefined

No result value.

Working Example

Example Snippetjavascript
const a=document.createElement("div"),b=document.createElement("div"),p=document.createElement("p");a.append(p);b.append(p);console.log(a.children.length,b.children.length);
JavaScript Reference