Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I want to select all the elements that have the two classes a and b.

<element class="a b">

So, only the elements that have both classes.

When I use $(".a, .b") it gives me the union, but I want the intersection.

1 Answer

0 votes
by (106k points)
edited by

If you want to select an element with multiple classes in jQuery then just write the selectors together without spaces in between them like below:-

$('.a.b')

Another thing the order is not relevant, so you can also swap the classes:

$('.b.a')

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...