Element: nextElementSibling 屬性
Element.nextElementSibling 只讀屬性會返回其父級 children 列表中緊跟在指定元素之後的那個元素,如果指定元素是列表中的最後一個元素,則返回 null。
值
一個 Element 物件,或者 null。
示例
html
<div id="div-01">Here is div-01</div>
<div id="div-02">Here is div-02</div>
js
let el = document.getElementById("div-01").nextElementSibling;
console.log("Siblings of div-01:");
while (el) {
console.log(el.nodeName);
el = el.nextElementSibling;
}
當此示例載入時,它會在控制檯輸出以下內容:
Siblings of div-01: DIV SCRIPT
規範
| 規範 |
|---|
| DOM # ref-for-dom-nondocumenttypechildnode-nextelementsibling② |
瀏覽器相容性
載入中…