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).
The . class selector can also be used to select multiple classes. Note: Seperate each class with a comma. Note: Do not start a class attribute with a number.
Use the getElementsByClassName method to get elements by multiple class names, e.g. document. getElementsByClassName('box green') . The method returns an array-like object containing all the elements that have all of the given class names.
You can specify any number of selectors to combine into a single result. This multiple expression combinator is an efficient way to select disparate elements. The order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.
$('.error.message')
should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With