🔰 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));
JavaScript: The Definitive Guide (15.3 Scripting Documents)
traversing DOM
Node
Last updated 2 years ago