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)?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

If you care about IE6, it (unsurprisingly) treats .class1.class2 exactly like .class2, see here for more: stackoverflow.com/questions/3772290/… Either way this is the correct selector. (Not an issue if you're using jQuery, though, only with pure CSS.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.