Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Element.append — appending nodes and text

`Element.append` adds nodes and text at the end of an element and returns `undefined`. If `a` and `b` are distinct elements, a successful call to `element.append(a, b, a)` leaves `b` followed by `a` at the end: the last occurrence of `a` moves the node rather than copying it. If instead `a` is a `DocumentFragment` containing one text node and `b` is a separate element, the first occurrence of `a` places the text node before `b` and empties the fragment. The last occurrence adds nothing, and the fragment itself is never inserted.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

element.append(...nodes)

Element.append comes from the DOM standard’s ParentNode mixin, not ECMAScript. It adds zero or more arguments after the element’s last child.

Strings become Text nodes, not HTML markup. An existing node is moved, not copied. A DocumentFragment contributes its children and becomes empty.

Unlike appendChild, append accepts multiple arguments, including text, and returns undefined. An invalid hierarchy, such as inserting an element into itself, causes HierarchyRequestError.

Examples

const box = document.createElement('div');
const label = document.createElement('span');
label.textContent = 'OK';
const result = box.append('Status: ', label, '!');
console.log(box.textContent);
console.log(box.childNodes.length);
console.log(result);

Result

Status: OK!
3
undefined

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources