CharacterData: nextElementSibling プロパティ
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.
nextElementSibling
は CharacterData
インターフェイスの読み取り専用プロパティで、親の子リストの中で、現在のノードの一つ後の Element
を返します。指定された要素がリストの最後のものであれば null
を返します。
値
Element
オブジェクト、または兄弟ノードが見つらなければ null
です。
例
html
TEXT
<div id="div-01">これは div-01 です</div>
TEXT2
<div id="div-02">これは div-02 です</div>
<pre>こちらは結果領域です</pre>
js
// 最初は、ノードに Text ノード `TEXT` を設定します
let node = document.getElementById("div-01").previousSibling;
let result = "TEXT の次の兄弟要素:\n";
while (node) {
result += `${node.nodeName}\n`;
node = node.nextElementSibling; // 最初のノードが CharacterData で、その他は Element オブジェクトです
}
document.querySelector("pre").textContent = result;
仕様書
Specification |
---|
DOM # ref-for-dom-nondocumenttypechildnode-nextelementsibling② |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
nextElementSibling |
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.