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.

nextElementSiblingCharacterData インターフェイスの読み取り専用プロパティで、親の子リストの中で、現在のノードの一つ後の 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 GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
nextElementSibling

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報