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