Document: replaceChildren() method


目录

{{APIRef("DOM")}}

The Document.replaceChildren() method replaces the existing children of a Document with a specified new set of children.

Syntax

replaceChildren(param1)
replaceChildren(param1, param2)
replaceChildren(param1, param2, /* …, */ paramN)

Parameters

Return value

None ({{jsxref("undefined")}}).

Exceptions

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:

document.replaceChildren();
document.children; // HTMLCollection []

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also


版本号 #2
由 壳壳虫 创建于 2026-10-31 03:27:53 UTC
由 壳壳虫 更新于 2026-10-31 03:27:53 UTC