HTML DOM Element insertAdjacentText() メソッド
- 前のページ insertAdjacentHTML()
- 次のページ insertBefore()
- 上一层に戻る HTML DOM Elements オブジェクト
定義と用法
insertAdjacentText()
指定された位置にテキストを挿入するメソッド。
合法な位置:
値 | 説明 |
---|---|
afterbegin | 要素の始めの後に(最初の子要素)。 |
afterend | 要素の後に。 |
beforebegin | 要素の前に。 |
beforeend | 要素の終わりの前に(最後の子要素)。 |
例
例1
タイトル要素の後ろにテキストを挿入:
const h2 = document.getElementById("myH2"); let text = "My inserted text"; h2.insertAdjacentText("afterend", text);
例2
"afterbegin"を使用:
const h2 = document.getElementById("myH2"); let text = "My inserted text"; h2.insertAdjacentText("afterbegin", text);
例3
"beforebegin"を使用:
h2.insertAdjacentText("beforebegin", text);
例4
"beforeend"を使用:
h2.insertAdjacentText("beforeend", text);
文法
element.insertAdjacentText(position, text)
または
node.insertAdjacentText(position, text)
パラメータ
パラメータ | 説明 |
---|---|
position |
必須。要素に対する位置:
|
text | 挿入するテキスト。 |
ブラウザのサポート
すべてのブラウザがサポートしています element.insertAdjacentText()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
サポート | サポート | サポート | サポート | サポート | サポート |
- 前のページ insertAdjacentHTML()
- 次のページ insertBefore()
- 上一层に戻る HTML DOM Elements オブジェクト