Use querySelectorAll in an option when there is more than one Select

Asked

Viewed 25 times

0

Good morning guys, everyone have a great holiday.

I have a javascript function that counts a list like this:

let counting = document.querySelectorAll("option:checked");

At first I thought it worked, but I saw that when I cleaned the list, there were still two items left in the count, which I found to be from other elements <select> that exist on the same page.

You can filter querySelectorAll, for example only count options, select has a specific id for example?

1 answer

1

In the end I found that I can pass 2 parameters in querySelectorAll so now my variable is like this:

let counting = document.querySelectorAll("#selection option:checked");

That’s the answer if someone looks for the same situation =]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.