How do I get all elements that have a specific label?

How do I get all elements that have a specific label?
0

#1

In my page, I have several elements with different ids and tags. However related elements have a similar label. What I want is to get all the elements with a label “cls” into an array. How can I achieve this?


#2

When you say label, do you mean label element? Do you have a link to your project, so we can see what you actually have?


#4

label is not a valid attribute in HTML. Why does the code have a label attribute? Did you write the code? Where does the code come from?


#7

OK, I learned something new today. I realized it could be use on the track element or the option element.

So, do you still need help? I have a solution in jQuery and can post a vanilla JS solution is a few minutes.


#8

Nope. I already got it for label and aria-label. Thanks for help though!


#9

What did you come up with?


#10

I used

var list = document.querySelectorAll('[label="cls"]');

#11

Yes, that would be the equivalent of doing the following in jQuery.

$("[label='cls']");