Extend little script so it adds a class to disabled?

Hi,

I have this little script to set a maximum number of checkboxes that can be checked.

Can I extend this so that the disabled checkboxes gets a class called “disabled”?

$("#friends input[type=checkbox]").click(function() {

    var bol = $("#friends input[type=checkbox]:checked").length >= 5;     
    $("#friends input[type=checkbox]").not(":checked").attr("disabled",bol);

});

Pass bol into .toggleClass: JSFiddle Demo

 $("#friends input[type=checkbox]").not(":checked").attr("disabled",bol).toggleClass('disabled', bol);
1 Like

thanks dude.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.