Last active
December 6, 2018 13:12
-
-
Save andreasvirkus/5b9ec6212bdde72de2e04eea7d4dcf08 to your computer and use it in GitHub Desktop.
A simple loop that traverses the DOM tree until it finds a parent with the specified 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
export const findParentByClass = (el, className) => { | |
while (el.parentNode) { | |
el = el.parentNode | |
if (el.classList && el.classList.contains(className)) return el | |
} | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment