title | short-title | slug | page-type | browser-compat |
---|---|---|---|---|
Document: replaceChildren() method |
replaceChildren() |
Web/API/Document/replaceChildren |
web-api-instance-method |
api.Document.replaceChildren |
{{APIRef("DOM")}}
The Document.replaceChildren()
method replaces the
existing children of a Document
with a specified new set of children.
replaceChildren(param1)
replaceChildren(param1, param2)
replaceChildren(param1, param2, /* …, */ paramN)
param1
, …,paramN
- : A set of {{domxref("Node")}} or string objects to replace the
Document
's existing children with. If no replacement objects are specified, then theDocument
is emptied of all child nodes.
- : A set of {{domxref("Node")}} or string objects to replace the
None ({{jsxref("undefined")}}).
HierarchyRequestError
{{DOMxRef("DOMException")}}- : Thrown if the constraints of the node tree are violated.
replaceChildren()
provides a very convenient mechanism for emptying a document
of all its children. You call it on the document without any argument specified:
document.replaceChildren();
document.children; // HTMLCollection []
{{Specifications}}
{{Compat}}
- {{domxref("Document.prepend()")}}
- {{domxref("Document.append()")}}