Last active
February 5, 2021 17:46
-
-
Save le717/df06db28787a31ebd1122ec6add94854 to your computer and use it in GitHub Desktop.
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
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