Created
March 2, 2016 13:59
-
-
Save arnorhs/91ddc91185dd5965473a to your computer and use it in GitHub Desktop.
random DOM utility functions
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
/** | |
* Given a Node. Find the first parent node that matches a selector | |
* | |
* @param node {Node} the base node who's parents will be traversed | |
* @param selector {string} asdfasdf | |
* @returns {Node|null} the node, or null if nothing was found | |
*/ | |
function findFirstParentNodeMatchingSelector(node, selector) { | |
var parent = node.parentNode; | |
if (parent === null) return null; | |
if (parent.matches(selector)) { | |
return parent; | |
} | |
return findFirstParentNodeMatchingSelector(parent, selector); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment