How to select an element with many classes with jQuery?

Ask a question+

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

<element class="a b">

Only the elements that have both classes.

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

BabkenM 1K
add comment

1 Answer


If you only want to match elements with both classes, just write the selectors together without spaces in between:


The order of the selectors is irrelevant, so this will work as well.


So to match a div element that has an ID of btn-google with classes login and button, you could write:

add comment

Your Answer