Reputation: 13486
I have HTML lets say like:
<ul>
<li class="test"></li>
<li class="test"></li>
<li class="test"></li>
<li></li>
</ul>
Now how can I test if there's one or more li
that has class test
?
$("li").hasClass("test");
doesn't seem to do the job...
Thanks
Upvotes: 1
Views: 110
Reputation: 5094
Now how can I test if there's one or more
li
that has classtest
?
$("li.test").size() > 0
means there is at least one li
that has the class test
.
Upvotes: 2
Reputation: 4024
If you have an li
selected you could use .is(".test")
If you want to know how many have that class you can do $("li.test").length
Upvotes: 1