Skip to content

Instantly share code, notes, and snippets.

@Sjeiti
Created July 3, 2015 09:22
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 Sjeiti/1ee7c1054dca8ef6004e to your computer and use it in GitHub Desktop.
Save Sjeiti/1ee7c1054dca8ef6004e to your computer and use it in GitHub Desktop.
querySelectorParents: traverse an elements parentNodes until the selector is matched
function querySelectorParents(elm,selector){
var result;
while ((elm=elm.parentNode)&&elm!==document) {
if (elm.matches(selector)) {
result = elm;
break;
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment