Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created February 1, 2011 18:17
Show Gist options
  • Save rgrove/806311 to your computer and use it in GitHub Desktop.
Save rgrove/806311 to your computer and use it in GitHub Desktop.
function getDescendants(node, includeSelf) {
var descendants = [],
i, len;
for (i = 0, len = node.children.length; i < len; ++i) {
descendants = descendants.concat(getDescendants(node.children[i], true));
}
if (includeSelf) {
descendants.push(node);
}
return descendants;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment