๐งnode.traverse()
๐ฐ JS โฉ browser โฉ DOM โฉ types โฉ Node โฉ .traverse()
๐พ replit: node.traverse()
// depth-first traversal
// ๐ธ node.traverse()
Node.prototype.traverse = function(f){
// do something on this node
f(this);
// and on its child nodes
for(let child of this.childNodes) {
child.traverse(f);
}
};
๐็ฏไพ๏ผ
document.traverse(elem => console.log(elem.nodeName));
Last updated
Was this helpful?