Search code examples
javascriptpolymershadow-dom

How do I traverse up out of shadow dom?


I have a structure:

<div>
    #shadow-root
        <span>

How do I reference the div from the span?

span.parentNode is the #shadow-root, and .parentNode from that is null


Solution

  • You can use shadowRoot.host to give you the <div>. Likewise, div.shadowRoot would get you the div's shadow root.