I have an ul
element. now I would like to know how many of li
's have selected
class .
<ul class="icon-list icon-list-inline star-rating" id="star-rating">
<li class="selected"></li>
<li class=""></li>
<li class=""></li>
<li class=""></li>
<li class=""></li>
</ul>
var vote_selected = $('#star-rating ... ???').length;
it must return 1 .
Try this :-
var vote_selected = $('#star-rating li[class="selected"]').length;
DEMO
Or (as li
is immediate descendents of #star-rating
you can use >
).
var vote_selected = $('#star-rating > li[class="selected"]').length;
Or
var vote_selected = $('#star-rating > .selected').length;
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