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

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?

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?

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?

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.

1 Like

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

What did you come up with?

I used

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

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

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