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② |
浏览器兼容性
加载中…