Web APIs
Element.prepend()
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
| Name | Type | Description |
|---|---|---|
| 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);