mercredi 22 juillet 2015

Toggle Checkbox settings

I've a table of elements and each has a line has a checkbox to opt-in or out. As the list of items can be very long i want to offer a "global" checkbox to tick all checkboxes or untick them based on the setting of this global checkbox. I have created jQuery code that does exactly that, but unfortunately only one time. I can't toggle the settings again and again. Any thoughts why? Thanks!

Here's my code:

jQuery('#ci-firmware-assign-toggle-checkbox').click(function(){
    if(jQuery('#ci-firmware-assign-toggle-checkbox').is(":checked")) {
        jQuery('tbody .ci-firmware-assign-checkbox').each(function(){
            if(!jQuery(this).attr("checked")) {
                jQuery(this).attr('checked', true);
            };
        });
    } else {
        jQuery('tbody .ci-firmware-assign-checkbox').each(function(){
            if(jQuery(this).attr("checked")) {
                jQuery(this).attr('checked', false);
            };
        });
    }
});




Aucun commentaire:

Enregistrer un commentaire