jQuery: Selector for all elements having two specific classes
Question by NetLabel | 2012-06-22 at 19:37
I am looking for a jQuery selector to select all elements that have assigned two specific classes. So for example:
<span class="a b"></span> [I only need this element] <span class="a"></span> <span class="b"></span>
In this example, I would like to select only the element, that has both classes, "a" as well as "b" (first line). Is that possible?
Related Topics
HTML: Difference between ID and CLASS
Info | 0 Comments
jQuery: Does an Element exist?
Tip | 1 Comment
jQuery: Count Elements, Images, Classes etc
Tip | 0 Comments
jQuery: One Selector for multiple Elements with different Classes
Question | 1 Answer
jQuery: Show and hide elements
Tutorial | 0 Comments
jQuery: Iterate over each element of a selector
Tip | 0 Comments
CSS: Include CSS Stylesheets in HTML
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
While you are using $(".a") for one class, you can simply connect the names of several classes with a dot in a row (without spaces) in order to select multiple classes:
In the same manner, you can also use this for elements with a specific ID:
This selects the element with the ID "c" and the two classes "d" and "e".
And for completeness:
This selects a DIV with the ID "c" and the classes "d" and "e", so for example this one here:
If you still need more than two classes, you can write them also to the row of classes connected with a dot.
2012-06-23 at 06:46