Document: replaceChildren() method
The Document.replaceChildren()
method replaces the
existing children of a Document
with a specified new set of children.
Syntax
js
replaceChildren(param1)
replaceChildren(param1, param2)
replaceChildren(param1, param2, /* …, */ paramN)
Parameters
Return value
None (undefined
).
Exceptions
HierarchyRequestError
DOMException
-
Thrown if the constraints of the node tree are violated.
Examples
Emptying a document
replaceChildren()
provides a very convenient mechanism for emptying a document
of all its children. You call it on the document without any argument specified:
js
document.replaceChildren();
document.children; // HTMLCollection []
Specifications
Specification |
---|
DOM Standard # ref-for-dom-parentnode-replacechildren① |
Browser compatibility
BCD tables only load in the browser