Skip to content

Instantly share code, notes, and snippets.

@KoryNunn
Last active December 15, 2015 03:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KoryNunn/5194180 to your computer and use it in GitHub Desktop.
Save KoryNunn/5194180 to your computer and use it in GitHub Desktop.
Simple closest element.
function closest(target, selector){
while(target && target.parentNode && Array.prototype.slice.apply(target.parentNode.querySelectorAll(selector)).indexOf(target)<0){
target = target.parentNode;
}
return target === document ? null : target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment