CharacterData: replaceWith() メソッド
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.
replaceWith()
は CharacterData
インターフェイスのメソッドで、親ノードの子リスト内にあるこのノードを、一連の Node
オブジェクトまたは文字列で置き換えます。
構文
js
replaceWith(nodes)
引数
返値
なし (undefined
)。
例外
HierarchyRequestError
DOMException
-
ノードが階層内の指定された位置に挿入できない場合に発生します。
例
html
<p id="myText">Some text</p>
js
let text = document.getElementById("myText").firstChild;
let em = document.createElement("em");
em.textContent = "Italic text";
text.replaceWith(em); // `Some text` を `Italic text` で置き換える
仕様書
Specification |
---|
DOM # ref-for-dom-childnode-replacewith① |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
replaceWith |
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.