$3.21

How to select an element with many classes with jQuery?

Ask a question+
1

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

2

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

$('.a.b')

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

$('.b.a')

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

$('div#btn-google.login.button')
add comment

Your Answer