Reputation: 5416
I want to be able to select all elements that only have a single (given) class (and no other)
for example, let's say my page looks like this
<html>
<body>
<div class="a"> </div>
<div class="a b"></div>
<div class="c"></div>
</body>
</html>
I want to be able to select only the first element - because it has a single class "a", and no other classes.
Thanks
Upvotes: 8
Views: 3752
Reputation: 254926
How about this:
$('.a[class="a"]')
or as @Hexa propsed:
$('div[class="a"]')
@Hexa: and it's actually the fastest! ;-) http://jsperf.com/attr-vs-attr-and-class
Upvotes: 14