JQuery counting elements with class "checked"

I struggle with that. I have a list of elements and part of the form, when something is checked, it adds the "checked" class to the corresponding list item.

<ul>
<li class="title">Checklist</li>
<li class="checkType checked">Card Type</li>
<li class="checkNumber checked">Card Number</li>
<li class="checkName checked">Name on Card</li>
<li class="checkMonth checked">Expiry Month</li>
<li class="checkYear checked">Expiry Year</li>
<li class="checkCode checked">Security Code</li>
</ul>

.title{font-size:23px; font-weight:bold;}
.checked{ color:#f00;}

But I need jQuery to verify that each element has an checkedEXCEPT class title.

Is this doable?

Demo: http://jsfiddle.net/bQtEQ/1/

Thanks to the answers, I now have the following

        var counting = $("li.checked:not(.title)").length;
    if (counting == 6){
        console.log(counting);
    }
+5
source share
4 answers

This can be done with 1 simple selector.

$("li.checked:not(.title)").length

, , , :not() . , jQuery dom. , .

+9

<li> 'checked', :

$('li.checked').not('.title').length

- :

$('.checked').length

.

+8
$('.checked').not('.title').length == $("ul li").length -1
+1
source
$("li").each(function() {
    if( !$(this).hasClass("title") && $(this).hasClass("checked") ) {
            alert("hah");
    }
 });
0
source

All Articles