jQuery Question

Disable a button in jquery if checkboxes with a certain class value are checked

I have checkboxes generated dynamically through php and i would like to hide a certain button if all the checkboxes having a similar class value are not checked and reenable it if they are checked:

The php code that generates the checkboxes is

<table class="table table-striped">

foreach ($checks as $m => $check) {
$item ="";
$checkbox ="";
$textinput ="";

if ($check->mandatory_customer == 1) { //mandatory customer checks
$displayx .="<i style='color:red;'>*</i>";
$item .= $check->item.$displayx;
$checkbox .='<input type="checkbox" class="1" id="'.$m.'"' ;
$textinput .='<input type="text" class="1" id="'.$m.'"' ;

} else { //not mandatory customer
$item .= $check->item;
$checkbox .='<input type="checkbox" class="0" id="'.$m.'"' ;
$textinput .='<input type="text" class="0" id="'.$m.'"' ;


echo "<tr id='" . $m . "'>";
echo "<td>" . $m . "</td>";
echo "<td>" . $item . "</td>";
echo "<td>".$checkbox."</td>";
echo "<td>".$textinput."</td>";
echo "</tr>";


I also have a button that i would like to disable if all checkboxes with class 1 are not checked and enable it if they are all checked using jquery

<button class="btn btn-success" id="approve_btn">Approve</button>

I have tried:

$('tbody tr').each(function () {
if ($(this).attr('class:1').find('.myCheckBox').prop('checked')) {
doEnableButton = true;
if (!doEnableButton) {
$('#approve_btn').prop('disabled', 'disabled')
else {


I have checked on several resources but most of them are not helpful
The above fails how do i go about this

Answer Source

Try this

    $(document).ready(function () {
        $(":checkbox.1").on("change", function () {
            if ($(":checkbox.1").not(":checked").length > 0)
                $("#approve_btn").prop("disabled", "disabled");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download