this fails:
var all_checkboxes = $('#myDiv input[type="checkbox"]');
if (all_checkboxes.is(':checked')) {
alert('they are all checked');
}
it alerts they are all checked even if just one and not all is checked.
this fails:
var all_checkboxes = $('#myDiv input[type="checkbox"]');
if (all_checkboxes.is(':checked')) {
alert('they are all checked');
}
it alerts they are all checked even if just one and not all is checked.
Share Improve this question asked Sep 9, 2011 at 18:51 SamSam 311 gold badge1 silver badge2 bronze badges 1- 2 possible duplicate of Finding all checkboxes are checked in jQuery – bzlm Commented Sep 9, 2011 at 18:53
3 Answers
Reset to default 10you can check if all your checkboxes are checked like this:
var all_checkboxes = $('#myDiv input[type="checkbox"]');
if (all_checkboxes.length === all_checkboxes.filter(":checked").length) {
alert('they are all checked');
}
Check that none of them are unchecked:
if (all_checkboxes.not(":checked").length === 0)
Just add a same class "myClass" to all the check boxes and then:
let areAllChecked = !$('.myClass').not(':checked').length; //'true' if all checked