How to get element in user-agent shadow root with JavaScript?

Yaroslav Polubedov picture Yaroslav Polubedov · Aug 1, 2016 · Viewed 25.7k times · Source

I need get elements from Shadow DOM and change it. How i can do it?

<div>
     <input type="range" min="100 $" max="3000 $">
</div>

Answer

Supersharp picture Supersharp · Aug 3, 2016

You cannot access a Shadow DOM created by the browser to display a control, that is called a #shadow-root (user-agent) in the Dev Tools. <input> is one example.

You can only access open custom Shadow DOM (the ones that you create yourself), with the { mode: 'open' } option.

element.attachShadow( { mode: 'open' } )

Update

It's true for most UX standard HTML elements: <input>, <video>, <textarea>, <select>, <audio>, etc.