tags:

views:

217

answers:

1

I have some message elements like this...

<span class="error message">Whoops!  Don't forget your name.</span>

And...

<span class="success message">All done!  Thank you very much.</span>

You'll notice that two classes are being applied to a single span element. This is valid markup. How can I select elements with two classes like this?

Note: I don't want all elements that have a class attribute containing "message". I need the elements that have both "error" and "message" (and nothing else).

+11  A: 
$('.error.message')

should do it.

JorenB
Note that this is also the correct syntax for a CSS definition for an element with multiple classes.
zombat
+1 Didn't know that :)
x3ro
Take a look at all the possibilities in CSS 3 Selectors - they're awesome. When taking into account the fact that jQuery supports pretty much all of them, it means you have awesome power over your DOM.
JorenB
As does Prototype in version 1.6.1 (due out any day), as both jQuery and Prototype use the same underlying **Sizzle** selection engine from John Resig.
T.J. Crowder