Count checked checkboxes
Count checked checkboxes
I have a jQuery object that contains a list of <input type="checkbox"> elements:
-
var boxes = $(whatever).find("input[type=checkbox]");
I need to know whether all of them are checked (just need true or false). This does work:
-
var all = true;
boxes.each(function(){
if( $(this).is(":not(:checked)") ){
all = false;
return;
}
});
However, I can't understand why I can't manage to do it using selectors. All these lines returns zero in all cases:
-
boxes.find(":checked").length
boxes.find(":is(:checked)").length
boxes.find(":not(:checked)").length
boxes.is(":checked").length
boxes.is(":is(:checked)").length
boxes.is(":not(:checked)").length
$(":checked", boxes).length
What's my mistake and/or misconception?