Pregunta

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?

¿Fue útil?

Solución

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']");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top