Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
-4
rated 0 times [  0] [ 4]  / answers: 1 / hits: 24161  / 9 Years ago, tue, february 2, 2016, 12:00:00

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>


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.


More From » jquery

 Answers
144

Try This



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


Or This also work



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

});

[#63472] Saturday, January 30, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
angelicajayleneh

Total Points: 216
Total Questions: 110
Total Answers: 100

Location: Sudan
Member since Tue, Aug 3, 2021
3 Years ago
;