Udara Udara - 5 months ago 78
jQuery Question

Bootstrap data-toggle="toggle" checked,unchecked by jquery

I'm using bootstrap checkbox with data-toggle="toggle" attribute. I want to set it checked and unchecked with jquery. I tried many ways but it didn't work. Here is my code.

<input type="checkbox" data-toggle="toggle" data-size="small" id="checkbox1">


for button click:

$("#checkbox").attr('checked',true);


But it's working when I remove
data-toggle="toggle"
attribute.


Any help is greatly appreciated!

Thanks.

Answer

From the documentation,

Use

$('#checkbox1').bootstrapToggle('on')

If you are using prop() or attr(), there is a workaround,

$('#checkbox1').prop('checked', true).change()
Comments