Created
September 4, 2022 04:09
-
-
Save avestura/f9235709719398305ff510c858cfcc18 to your computer and use it in GitHub Desktop.
Closest get past shadow dom
This file contains hidden or 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
const isShadowRoot = (maybeRoot) => { | |
return maybeRoot && maybeRoot.toString() === '[object ShadowRoot]' | |
} | |
const closestPastShadowDom = (elem, selector) => { | |
const closest = elem.closest(selector); | |
if(closest) | |
return closest; | |
const root = elem.getRootNode(); | |
if(isShadowRoot(root)) { | |
return closestPastShadowDom((root).host, selector) | |
} | |
return undefined; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment