Last active
November 6, 2015 22:14
-
-
Save electerious/b045e45572c463756b2c to your computer and use it in GitHub Desktop.
Select the closest matching parent of an element
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
const closest = (elem, className) => { | |
if (elem==null || elem.classList==null) return null | |
return (elem.classList.contains(className) ? elem : closest(elem.parentNode, className)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
Alternatives: