Movatterモバイル変換


[0]ホーム

URL:


  1. 開発者向けのウェブ技術
  2. Web API
  3. Element
  4. after()

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。

View in EnglishAlways switch to English

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 ノードと等価なノードとして挿入されます。

構文

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①

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp