Skip to content

Instantly share code, notes, and snippets.

@mgechev
Last active November 2, 2015 09:49
Show Gist options
  • Select an option

  • Save mgechev/1454c83c42bfd18b0e92 to your computer and use it in GitHub Desktop.

Select an option

Save mgechev/1454c83c42bfd18b0e92 to your computer and use it in GitHub Desktop.
function traverse(node) {
return Promise.all([].slice.call(node.children).map(function (c) {
return Promise.resolve(c);
}))
.then(function (nodes) {
return Promise.all(nodes.map(traverse))
.then(function (els) {
return els.reduce(function (prev, arr) {
return arr.concat(prev);
}, []).concat(nodes);
});
});
}
traverse(document.body).then(function (res) {
res.map(function (e) {
console.log(e.tagName);
});
});
@zzz6519003
Copy link

how did this magic happens?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment