Tuesday, May 29, 2012

jQuery multiple class selector

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.

Source: Tips4all


  1. This should work:


    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:


  2. You can do this using the filter function: