views:

7770

answers:

2

Hi guys,

I want to select all the elements that have these two classes 'a' and 'b'. So, only the elements that have both classes. When I use $(".a, .b") it gives me union, but I want intersection.

+45  A: 

This should work:

$('.a.b')

If you want an intersection, just write the selectors together without spaces in between. So for something that has ID 'a' and classes 'b' and 'c', you'd do:

$('#a.b.c')
musicfreak
+1  A: 

You can do this using the filter function:

$(".a").filter(".b")
Jamie Love