mercredi 13 septembre 2017

Get checked state of a switchery checkbox in jquery

I have the following code:

<div class="form-group col-xs-1">
  <label for="closed" class="control-label">Hide closed</label>
  <input name="closed" type="checkbox" id="closed" class="form-group js-switch" checked /> 
</div>

$('#closed').on('change', function() {
      if ($('#closed').is(':checked')) {
        closed = 1;
      } else {
        closed = 0;
      }
      console.log(closed);
    });

But when I change the status of the checkbox, I always see false.

Aucun commentaire:

Enregistrer un commentaire