Created
February 29, 2012 04:46
-
-
Save jondavidjohn/1937831 to your computer and use it in GitHub Desktop.
My Solution to http://jsfiddle.net/jondavidjohn/9WpZ6/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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