递归遍历dom树
2022-01-24 本文已影响0人
Mr老朝
var walk_the_DOM = function walk(node, func) {
func(node);
node = node.firstChild;
while(node) {
walk(node, func);
node = node.nextSibling
}
}
walk_the_DOM(document.body, (node) => {
console.log(node)
})