mardi 2 février 2016

jquery checkbox checked toggle when click of a button

I want to toggle the checkbox on click of button.

Here is my jQuery

$("#choose_address2").on("click", function () { 
   console.log("click!!! address2");
   var $checkbox = $(this).find(':checkbox');
   var checkBoxes = $("input[name=checkbox]]");
   checkBoxes.prop("checked", !checkBoxes.prop("checked"));
});

Here is my Input

<span id="choose_address2" class="btn btn-info"><i class="fa fa-plus-circle"></i>เพิ่มที่อยู่<input type="checkbox" name="choose_address" {{#if customer.addresses}}checked{{/if}} id="choose_address1" hidden></input></span><br>

By default the button is checked. however when i click the span with id choose_address2 i want to change the state. Any suggestions will be highly appreciated




Aucun commentaire:

Enregistrer un commentaire