Web APIs
Element.replaceChildren()
Replace all children with the supplied nodes or text. With no arguments, empty the element. Example console output: new 0.
Formal Syntax & Structure
javascript syntaxjavascript
element.replaceChildren(...nodes)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| nodes | (Node or string)[] | Variadic replacement nodes or text. |
Return Value
undefined
No result value.
Working Example
Example Snippetjavascript
const p=document.createElement("p"); p.append(document.createElement("b")); p.replaceChildren("new"); console.log(p.textContent,p.children.length);