Skip to content Skip to sidebar Skip to footer

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 :

  1. If there's a Shadow DOM (shadowRoot not null), parse the Shadow tree.
  2. 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"