DOM

Element.insertAdjacentText() メソッド

 編集:2022.09.22 by T.A.

[Edge]。→

element の開始タグまたは終了タグの隣に指定のテキストを挿入します。

構文
element.insertAdjacentText(where, text)
Element Element
where DOMStringelementを基準とした挿入位置。
指定挿入位置
beforeBegin 開始タグの前
afterBegin 開始タグの後
beforeEnd 終了タグの前
afterEnd 終了タグの後
text DOM ツリーに挿入するテキストの DOMString 表現。
戻り値

Void。¶戻り値なし

例外
SyntaxError
whereの挿入位置として指定した文字列が認識できない値だった。

HTML:

<DIV id=IdSoto>[DIV要素
<SPAN id=IdTest>[SPAN要素]</SPAN>
]
</DIV>

JavaScript:

D=IdTest.insertAdjacentText("beforeBegin", "テキスト<B>[B要素&plusmn;]</B>"); //開始タグの前にテキストを挿入。
DA=IdSoto.innerHTML;           //挿入後の結果をHTMLコード文字列で表示。
	//=[string]:[DIV要素 テキスト&lt;B&gt;[B要素&amp;plusmn;]&lt;/&><span id="IdTest">[SPAN要素]</span> ]
関連

insertAdjacentHTML()insertAdjacentElement()append()


テスト