Last active
March 25, 2016 18:47
-
-
Save azinasili/3dd50a9520f9176f9c98 to your computer and use it in GitHub Desktop.
Find ancestor element by class.
This file contains hidden or 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
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