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