Skip to content

Instantly share code, notes, and snippets.

@le717
Last active February 5, 2021 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le717/df06db28787a31ebd1122ec6add94854 to your computer and use it in GitHub Desktop.
Save le717/df06db28787a31ebd1122ec6add94854 to your computer and use it in GitHub Desktop.
export function find_parent(element, selector) {
// The desired element was not found on the page
if (element === null) {
return null;
}
// We found the desired element
if (element.matches(selector)) {
return element;
// Keep searching for the element
} else {
return find_parent(element.parentElement, selector);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment