lundi 24 août 2015

Getting checked checkboxes with jQuery

I have a function that is supposed to catch changes to all checkboxes. It works when the boxes are clicked manually, but does not work when the toggleAll() function triggers them.

Anyway to correct this?

$(function() {
    $(":checkbox").change(function(){
    if ( this.checked ) {
        alert(this.id+' is checked');
    } else {
        alert(this.id+' is not checked');
    }
    });
});

function toggleAll() {
    var selectAllCheckbox = $("#selectAllCheckbox");
    if ( selectAllCheckbox.prop('checked') ) {
        // uncheck them all
        $("[id^=friendRequestCheckbox]").attr('checked', false);
    } else {
        // check them all
        $("[id^=friendRequestCheckbox]").attr('checked', true);
    }
}

I am running an old version of jQuery and have not updated to the new version including prop, just in case that's relevant.




Aucun commentaire:

Enregistrer un commentaire