Select All checkboxes using jQuery

前端 未结 15 1594
渐次进展
渐次进展 2020-12-05 06:26

I have the following html code:

    
    

15条回答
  •  一生所求
    2020-12-05 07:04

    checkall is the id of allcheck box and cb-child is the name of each checkboxes that will be checked and unchecked depend on checkall click event

    $("#checkall").click(function () {
                            if(this.checked){
                                $("input[name='cb-child']").each(function (i, el) {
                                    el.setAttribute("checked", "checked");
                                    el.checked = true;
                                    el.parentElement.className = "checked";
    
                                });
                            }else{
                                $("input[name='cb-child']").each(function (i, el) {
                                    el.removeAttribute("checked");
                                    el.parentElement.className = "";
                                });
                            }
                        });
    

提交回复
热议问题