Skip to content

Instantly share code, notes, and snippets.

@zhanhongtao
Created May 8, 2015 01:00
Show Gist options
  • Save zhanhongtao/ad513846fdc5d9456fb8 to your computer and use it in GitHub Desktop.
Save zhanhongtao/ad513846fdc5d9456fb8 to your computer and use it in GitHub Desktop.
遍历 DOM 树
function walk(root, handle) {
if (!root) return;
if (root.nodeType !=1 && root.nodeType != 11) return;
for (var node = root.firstChild; node; node = node.nextSibling) {
walk(node, handle);
handle(node);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment