utils/dom/getshadowroots
module
Functions
getShadowRoots( node ) → Array<ShadowRoot>module:utils/dom/getshadowroots~getShadowRootsReturns every shadow root the given node renders in, innermost first.
For code that has to act on all the shadow boundaries above a node – attaching listeners, injecting styles – rather than only the nearest one. Empty for a node in the light DOM, and one entry per boundary for a node inside nested trees. Works for open and closed roots alike.
Derived from the tree the node sits in, not from whether that tree is in a document: a node inside a shadow root reports that root even while its host is detached, because
attachShadow()makes the shadow tree – and its root – real right away. Callers that only care about the roots a node is currently rendered in should checkNode#isConnectedthemselves.Parameters
node: NodeThe node to collect the hosting shadow roots of.
Returns
Array<ShadowRoot>