5

Is it possible in jQuery or CSS (since I think they use the same selector logic) to say select elements that have multiple classes. For example:

<div class='class1'></div>
<div class='class2'></div>
<div class='class1 class2'></div>

Is there a way I can say I want elements that are of both class1 and class2 (therefore only get the third div in this case)?

ScottE
  • 21,530
  • 18
  • 94
  • 131
jhchen
  • 14,355
  • 14
  • 63
  • 91

1 Answers1

12

The selector you are looking for is .class1.class2

For more info, check out the spec: http://www.w3.org/TR/CSS2/selector.html#class-html

Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
  • 1
    If you care about IE6, it (unsurprisingly) treats `.class1.class2` exactly like `.class2`, see here for more: http://stackoverflow.com/questions/3772290/css-selector-that-applies-to-elements-with-two-classes/3772305#3772305 Either way this is the correct selector. (Not an issue if you're using jQuery, though, only with pure CSS.) – BoltClock Jan 03 '11 at 00:41