Created
January 8, 2019 09:54
-
-
Save Christilut/835de75af104b82daf0b207efa69877d to your computer and use it in GitHub Desktop.
Javascript function to check if target is inside parent selector
This file contains 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 hasParentWithMatchingSelector(target, selector) { | |
return [...document.querySelectorAll(selector)].some(el => | |
el !== target && el.contains(target) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment