このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
Element: after() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2018年4月.
Element.after() は、一連のNode オブジェクトまたは文字列をこのElement の親の子リストの、Element の直後に挿入します。文字列はText ノードと等価なノードとして挿入されます。
In this article
構文
js
after(node1)after(node1, node2)after(node1, node2, /* … ,*/ nodeN)引数
node1, …,nodeN挿入する一連の
Nodeオブジェクトまたは文字列です。
返値
なし (undefined)。
例外
HierarchyRequestErrorDOMExceptionノードが階層構造の中の指定された位置に挿入できなかったときに発生します。
例
>要素の挿入
js
let container = document.createElement("div");let p = document.createElement("p");container.appendChild(p);let span = document.createElement("span");p.after(span);console.log(container.outerHTML);// "<div><p></p><span></span></div>"テキストの挿入
js
let container = document.createElement("div");let p = document.createElement("p");container.appendChild(p);p.after("Text");console.log(container.outerHTML);// "<div><p></p>Text</div>"要素とテキストの挿入
js
let container = document.createElement("div");let p = document.createElement("p");container.appendChild(p);let span = document.createElement("span");p.after(span, "Text");console.log(container.outerHTML);// "<div><p></p><span></span>Text</div>"仕様書
| Specification |
|---|
| DOM> # ref-for-dom-childnode-after①> |