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