Reputation: 1318
Is there a substitute for querySelectorAll in Polymer?
I like to do many stuff programmatically and for single elements I use:
ButtonElement b2 = $["b2"];
But if I want to get several radiobuttons, I can't use the usual
List<InputElement> radios = querySelectorAll("[name='func']");
radios.forEach((f) {
f.onClick.listen((e) => changeFunction(f,e));
});
Should I be doing it in a different way?
Upvotes: 2
Views: 1675
Reputation: 11171
ShadowRoot
(which extends DocumentFragment
), and Element
both have querySelector
and querySelectorAll
that are scoped properly.
For a custom element, which you use depends on whether you want to query the light or shadow DOM, but since you are using $[]
, you probably want to use the shadow root.
Try this:
List<InputElement> radios = shadowRoot.querySelectorAll("[name='func']");
Upvotes: 5