• support@answerspoint.com

How can I select an element with multiple classes?

1758

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


 

So, only the elements that have both classes.

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

2Answer


0

If you want an intersection, just write the selectors together without spaces in between.

$('.a.b')

So for an element that has an ID of a with classes b and c, you would write:

$('#a.b.c')
  • answered 8 years ago
  • Gul Hafiz

0

You can do this using the filter function:

$(".a").filter(".b")
  • answered 8 years ago
  • Gul Hafiz

Your Answer

    Facebook Share        
       
  • asked 8 years ago
  • viewed 1758 times
  • active 8 years ago

Best Rated Questions