Skip to content

Instantly share code, notes, and snippets.

@arnorhs
Created March 2, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnorhs/91ddc91185dd5965473a to your computer and use it in GitHub Desktop.
Save arnorhs/91ddc91185dd5965473a to your computer and use it in GitHub Desktop.
random DOM utility functions
/**
* 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