Elements
Advanced
Exercise 11 of 31
Shadow DOM
Find and use elements that live inside shadow roots.
1. Open shadow root
The card below is a custom element. Its input, button and result are inside an open shadow root, so document.querySelector('#shadow-input') returns null. In DevTools you see them under #shadow-root (open).
2. Nested shadow root
Inside the card above there is a second custom element, <mc-badge id="nested-host">, with its own shadow root containing #nested-button and #nested-count. You need to go through two shadow roots to reach them.
3. Closed shadow root
This element uses a closed shadow root: host.shadowRoot is null and test tools cannot locate the elements inside. The page reports clicks in the light DOM status below, so you can still assert on it.
Status: Not clicked yet