CKTIS / JavaScript
Element.prepend — inserting at the start of an element
Element.prepend inserts nodes and text before an element’s first child. If a and b are distinct elements, prepend(a, b, a) inserts b followed by a, without duplicating a.
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.prepend(...nodes)Element.prepend is a DOM method from the ParentNode mixin, not an ECMAScript function. It accepts nodes and strings; it returns undefined.
Arguments go before the first child, including a text child. Strings become Text nodes, not HTML markup. Existing nodes are moved, not copied.
Violating tree hierarchy constraints throws HierarchyRequestError. The example requires a DOM environment; a Node.js version alone does not establish availability of this method.
Examples
const container = document.createElement('div');
const label = document.createElement('span');
label.textContent = 'Start';
container.textContent = 'End';
const result = container.prepend(label, ' | ');
console.log(container.textContent);
console.log(container.firstChild === label);
console.log(result === undefined);Result
Start | End true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.