TreeWalker: nextSibling() 方法
TreeWalker.nextSibling() 方法會將當前 Node 移動到其下一個同級節點(如果存在),並返回找到的同級節點。如果不存在這樣的節點,則返回 null,並且當前節點不會被更改。
語法
js
nextSibling()
引數
無。
返回值
一個 Node 物件或 null。
示例
js
const treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ELEMENT,
{
acceptNode(node) {
return NodeFilter.FILTER_ACCEPT;
},
},
false,
);
treeWalker.firstChild();
const node = treeWalker.nextSibling(); // returns null if the first child of the root element has no sibling
規範
| 規範 |
|---|
| DOM # dom-treewalker-nextsibling |
瀏覽器相容性
載入中…
另見
- 它所屬的
TreeWalker介面。