Udara Udara - 1 year ago 160
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:


But it's working when I remove

Any help is greatly appreciated!


Answer Source

From the documentation,



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

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