开发者

How to check if all checkboxes inside a div are checked using jQuery?

this fails:

var all_checkboxes = $('#myDiv input[type="checkbox"]');

if (all_checkboxes.is(':checked')) {
   alert('they are all checked');
}

it ale开发者_开发知识库rts they are all checked even if just one and not all is checked.


you 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜