CharacterData.nextElementSibling
nextElementSibling
は CharacterData
インターフェイスの読み取り専用プロパティで、親の子リストの中で、現在のノードの一つ後の Element
を返します。指定された要素がリストの最後のものであれば null
を返します。
値
Element
オブジェクト、または兄弟ノードが見つらなければ null
です。
例
TEXT
<div id="div-01">Here is div-01</div>
TEXT2
<div id="div-02">Here is div-02</div>
<pre>Here is the result area</pre>
// Initially, set node to the Text node with `TEXT`
let node = document.getElementById('div-01').previousSibling;
let result = 'Next element siblings of TEXT:\n';
while (node) {
result += node.nodeName + '\n';
node = node.nextElementSibling; // The first node is a CharacterData, the others Element objects
}
document.getElementsByTagName('pre')[0].textContent = result;
仕様書
Specification |
---|
DOM Standard # ref-for-dom-nondocumenttypechildnode-nextelementsibling② |
ブラウザーの互換性
BCD tables only load in the browser