Jquery Check parent checkboxes in nested ul li

后端 未结 5 1959
情话喂你
情话喂你 2021-01-02 12:48

I have a script that will check and uncheck all children checkboxes in a nested list. I am now trying to get it so I can check a low level checkbox and it will check all the

5条回答
  •  一向
    一向 (楼主)
    2021-01-02 12:55

    Have a JSFiddle: http://jsfiddle.net/3y3Pb/16/

    I would recommend adding a parent attribute to the checkboxes. This parent attribute will reference the parent checkbox's id so that you don't have to worry about your structure changing:

    $('input type=[checkbox]').change(function () {
        $('#' + $(this).attr('parent')).prop('checked', this.checked);
    });
    

    Ex:

    Account Settings
        
    • AS One

提交回复
热议问题