Web APIs

Element.prepend()

Try the free JavaScript compiler

Insert nodes or literal strings before existing children. Strings become text nodes. Example console output: hello world.

Formal Syntax & Structure

javascript syntaxjavascript
element.prepend(...nodes)

Parameters & Attributes

NameTypeDescription
nodes(Node or string)[]Variadic nodes or text.

Return Value

undefined

No result value.

Working Example

Example Snippetjavascript
const p=document.createElement("p"); p.append("world"); p.prepend("hello "); console.log(p.textContent);
JavaScript Reference