Skip to content

Instantly share code, notes, and snippets.

@jahilldev
Last active September 13, 2022 13:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Function to match an element via a target selector in the provided tree. Useful for event delegation.
function isTargetElement(element, selector) {
let target = element;
while (target) {
if (target?.matches && target?.matches(selector)) {
break;
}
target = target?.parentNode;
}
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment