[solved] Smart Select - select all checkbox


#1

I did all the check boxes to select. Is there a better way?

   $(document).on('change', '.smart-select-sheet .item-checkbox input[type="checkbox"]', function () {
            var box = $(this).prop('checked');
            var val = $(this).val();

            if (val == 'all') {
                $(this).parents('ul').find('input[type="checkbox"]').filter(function (index, el) {
                    if (index != 0) {
                        if ($(el).prop('checked') == !box) $(el).click();
                    }
                });
            } else {
                if (box == false) {
                    var all = $(this).parents('ul').find('input[value="all"]');
                    if (all.prop('checked') == true) {
                        all.click();
                        $(this).prop('checked',!box).click();
                    }
                }
            }
        });

#2

But instead of .click() it is better to .trigger('change') like:

$(this).prop('checked',!box).trigger('change');

#3

Works perfectly. Thank you. last edited code :

$(document).on('change', '.smart-select-sheet .item-checkbox input[type="checkbox"]', function () {
var box = $(this).prop('checked');
var val = $(this).val();
var all = $(this).parents('ul').find('input[value="all"]');    
if (val == 'all') {
    $(this).parents('ul').find('input[type="checkbox"]').filter(function (index, el) {
        if (index != 0) {
             $(el).prop('checked',box).trigger('change');
        }
    });
} else {
    if (box == false) {
        if (all.prop('checked') == true) {  
            all.prop('checked',false).trigger('change');
            $(this).prop('checked', true).trigger('change');
        }
    }
}
});