This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2020.
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, …, paramNA set of Node objects or strings to replace the Document's existing children with. If no replacement objects are specified, then the Document is emptied of all child nodes.
None (undefined).
HierarchyRequestError 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 []
| Specification |
|---|
| DOM> # ref-for-dom-parentnode-replacechildren①> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
replaceChildren |
86 | 86 | 78 | 72 | 14 | 86 | 79 | 61 | 14 | 14.0 | 86 | 14 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document/replaceChildren