Skip to content

Instantly share code, notes, and snippets.

@jondavidjohn
Created February 29, 2012 04:46
Show Gist options
  • Save jondavidjohn/1937831 to your computer and use it in GitHub Desktop.
Save jondavidjohn/1937831 to your computer and use it in GitHub Desktop.
//
// Start Method Definitions
//
// match_selector(Node tree, Array selectors)
// - top of the node tree
// - array of decendant string selectors (think CSS)
//
var match_selector = function self(node, selectors) {
if ( node.values.indexOf(selectors[0]) !== -1 ) {
if (selectors.length > 1) {
selectors.shift();
}
else {
output(node);
}
}
for (var i = 0, len = node.children.length; i < len; i++) {
self(node.children[i], selectors.slice());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment