vendredi 15 septembre 2017

How can I enable/disable a checkbox next to another checkbox?

If I check one of the left checkboxes, I want that the checkbox right next to it will be enabled. If I uncheck one of the left checkboxes, the checkbox right next to it should be disabled again:

$('input[type="checkbox"]').change(function () {
   $("input:checkbox:checked:not(.delivery)").each(function () {
      if ($("input:checkbox:checked").length > 0) {
        $(this).closest("tr").children('.disable').removeAttr("disabled");
      } else {
         $(this).closest("tr").children('.disable').addAttr("disabled");
      }
   });
});
<script src="http://ift.tt/1oMJErh"></script>
<tr>
   <td><input  type="checkbox"></td>
   <td><input class="disable" disabled="" type="checkbox"></td>
</tr>
<br>
<tr>
  <td><input  type="checkbox"></td>
  <td><input class="disable" disabled="" type="checkbox"></td>
</tr>

With my code, it keeps disabled.




Aucun commentaire:

Enregistrer un commentaire