all checkboxes need to be checked and unchecked with the main checkbox

后端 未结 3 398
一生所求
一生所求 2021-01-15 18:58

Can anyone help me with this?

I have two divs. In one div, I have a checkbox named allcheck, and in the other other div<

3条回答
  •  滥情空心
    2021-01-15 19:35

    This code implements functionality to select and deselect all checkboxes

    select and deselect

    $(".select-all-checkbox").click(function () {
           $('input:checkbox').prop('checked', this.checked);
       });
    

    If one item deselect then button CheckAll is UnCheck

    $(".mainCheckboxClass")
            .click(
                    function() {
                        if ($('input[class=mainCheckboxClass]:checked').length === $('input[class=mainCheckboxClass]').length)
                            $('.select-all-checkbox').prop("checked", true);
                        else
                            $('.select-all-checkbox').prop("checked", false);
    });
    

提交回复
热议问题