Skip to content

Instantly share code, notes, and snippets.

@Christilut
Created January 8, 2019 09:54
Show Gist options
  • Save Christilut/835de75af104b82daf0b207efa69877d to your computer and use it in GitHub Desktop.
Save Christilut/835de75af104b82daf0b207efa69877d to your computer and use it in GitHub Desktop.
Javascript function to check if target is inside parent selector
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