const treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ELEMENT,
{
acceptNode(node) {
return NodeFilter.FILTER_ACCEPT;
},
},
false,
);
const node = treeWalker.nextNode(); // returns the first child of root, as it is the next node in document orderTreeWalker: nextNode() method / notebook
TreeWalker: nextNode() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.