How to find and check all dynamic child checkboxes in tree using jquery?

后端 未结 3 1953
滥情空心
滥情空心 2021-01-14 13:36

I have added check-boxes dynamically to all the element and successfully added the functionality to select all checkboxes but not able to do the selection for the parent chi

3条回答
  •  有刺的猬
    2021-01-14 14:06

    The following will check all children checkboxes, deeper than 1 level using find rather than children.

    $(document.body).on('change', 'input[type=checkbox]', function(){
        if($(this).is(':checked')){
            $(this).find('input[type="checkbox"]').prop('checked', true);
        }
    });
    

提交回复
热议问题