CharacterData:nextElementSibling 属性
CharacterData 接口的只读 nextElementSibling 属性返回指定节点在父节点子节点列表中紧随其后的第一个 Element 节点,如果指定节点是列表中的最后一个节点,则返回 null。
值
一个 Element 对象,如果没有找到同胞节点,则为 null。
示例
html
TEXT
<div id="div-01">Here is div-01</div>
TEXT2
<div id="div-02">Here is div-02</div>
<pre>Here is the result area</pre>
js
// Initially, set node to the Text node with `TEXT`
let node = document.getElementById("div-01").previousSibling;
let result = "Next element siblings of TEXT:\n";
while (node) {
result += `${node.nodeName}\n`;
node = node.nextElementSibling; // The first node is a CharacterData, the others Element objects
}
document.querySelector("pre").textContent = result;
规范
| 规范 |
|---|
| DOM # ref-for-dom-nondocumenttypechildnode-nextelementsibling② |
浏览器兼容性
加载中…