Document: replaceChildren() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Document.replaceChildren()
メソッドは Document
の既存の子を指定した新しい子で置き換えます。
構文
js
replaceChildren(param1)
replaceChildren(param1, param2)
replaceChildren(param1, param2, /* …, */ paramN)
引数
param1
, …,paramN
-
一連の
Node
または文字列オブジェクトで、これがDocument
の既存の子ノードを置き換えます。置き換えるオブジェクトを指定しなかった場合は、Document
からすべての子ノードを削除します。
返値
なし (undefined
)。
例外
HierarchyRequestError
DOMException
-
ノードツリーの制約に違反した場合に発生します。
例
文書を空にする
replaceChildren()`は、文書の子要素をすべて空にするとても便利なメカニズムを提供します。引数を指定しないで、文書に対して呼び出すのです。
js
document.replaceChildren();
document.children; // HTMLCollection []
仕様書
Specification |
---|
DOM # ref-for-dom-parentnode-replacechildren① |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
replaceChildren |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.