Plain Javascript Code That Does What QuerySelector() And QuerySelectorAll() Does, Include Shadowroots
I am trying to write a method that takes in two params: one of the parentNode of the current element where many childNodes with shadowroots within it, the second param being the id
Solution 1:
You must create a parser that will check recursively the DOM :
For each node :
- If there's a Shadow DOM (
shadowRoot
notnull
), parse the Shadow tree. - Or else parse the children DOM tree.
If you use <slot>
you'll have look for distributed nodes too, but it's not asked in your question...
Post a Comment for "Plain Javascript Code That Does What QuerySelector() And QuerySelectorAll() Does, Include Shadowroots"