What is DOMElement.shadowRoot? What does it do? Why does it return null? What can it be used for?
document.body.shadowRoot
I tried searching but I can't understand what it does.
What is DOMElement.shadowRoot? What does it do? Why does it return null? What can it be used for?
document.body.shadowRoot
I tried searching but I can't understand what it does.
It's a container for the "internal DOM" (i.e. the shadow DOM) of native elements such as <input>
or <button>
(or custom elements made with the web components APIs).
When you inspect <input>
you only see the <input>
itself:
But you can turn on a flag in the Chrome Dev Tools to enable the visibility of the shadow DOM:
You can now see how the <input>
is "implemented" by the browser. For example the placeholder is contained within a <div>
element: