Skip to content

Instantly share code, notes, and snippets.

@azinasili
Last active March 25, 2016 18:47
Show Gist options
  • Save azinasili/3dd50a9520f9176f9c98 to your computer and use it in GitHub Desktop.
Save azinasili/3dd50a9520f9176f9c98 to your computer and use it in GitHub Desktop.
Find ancestor element by class.
function findAncestor(el, cls) {
if (el === document) {
return false;
}
if (el.classList.contains(cls)) {
return true;
}
return el.parentNode && findAncestor(el.parentNode, cls);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment