Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  31] [ 4]  / answers: 1 / hits: 52093  / 8 Years ago, mon, august 1, 2016, 12:00:00

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



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

More From » html

 Answers
30

Here is an example:



var container = document.querySelector('#example');
//Create shadow root !
var root = container.createShadowRoot();
root.innerHTML = '<div>Root<div class=test>Element in shadow</div></div>';

//Access the element inside the shadow !
//container.shadowRoot represents the youngest shadow root that is hosted on the element !
console.log(container.shadowRoot.querySelector(.test).innerHTML);


Demo:





var container = document.querySelector('#example');
//Create shadow root !
var root = container.createShadowRoot();
root.innerHTML = '<div>Root<div class=test>Element in shadow</div></div>';

//Access the element inside the shadow !
console.log(container.shadowRoot.querySelector(.test).innerHTML);

<div id=example>Element</div>





I hope this will help you.


[#61188] Thursday, July 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianod

Total Points: 667
Total Questions: 106
Total Answers: 92

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
lucianod questions
;