How to remove the attribute "disabled='disabled' submit button using id='bla' if at least one checkbox with class='check' checked?
"disabled='disabled'
id='bla'
class='check'
If the check box is not selected, the disabled attribute should return to the submit button.
You just need to check the length property of the checked array
length
$('.check').change(function() { if ($('.check:checked').length) { $('#sub').removeAttr('disabled'); } else { $('#sub').attr('disabled', 'disabled'); } });
Here's the demo: http://jsfiddle.net/LUnN5/
Get a link to all the relevant check boxes, and then set the disabled property in the change() event based on whether any of these check boxes are selected.
disabled
change()
var checks = $(':checkbox.check'); checks.change(function() { $('#bla').attr('disabled', ! checks.filter(':checked').length); });
jsFiddle .
$(".check").change(function() { var btn = $("#bla"); if ($(".check").is(":checked")) { btn.removeAttr("disabled"); } else { btn.attr("disabled", "disabled"); } }); $(".check").triggerHandler("change");