简体   繁体   中英

get all elements by class name in polymer

Can someone please tell me how to get all elements by class name in polymer? We can surely is this.$$(selector) , but in the documentation it is clearly mentioned that $$ returns the first node in the local DOM that matches selector .

`

Polymer 1:

Use this.$$('class-name') to get the all DOM Elements using the class name.

Polymer 2:

Use this.shadowRoot.querySelector('class-name') to get the DOM Elements.

I hope it's helpful to you.

The this.$$() is a shorthand for Polymer.dom(this.root).querySelector() .
What you are looking for is the query select all. Which would look like this: Polymer.dom(parent).querySelectorAll(selector)
In Polymer 1 this worked. However, I did not test in in version 2. You might have to use this.shadowRoot and wait until the shadow DOM is initialized


You can find further information on that in the Polymer Documentation under DOM API & Query selectors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM