I am using Bootstrap Switch in my project to show a warning flag. Each time I try to set value of switch from false to true dynamically it is not going in .bootstrapSwitch().on
method. It is working fine on changing switch state from false to true dynamically. Fiddle below-
Asked
Active
Viewed 4,810 times
0

nickalchemist
- 2,211
- 6
- 31
- 58
-
Click 'Off', it alerts false. Now click 'On', its not alerting – nickalchemist Aug 12 '15 at 10:58
-
$('#bootstrapswitch').bootstrapSwitch('state', false, false); $('#bootstrapswitch').bootstrapSwitch('state', true, true); – nickalchemist Aug 12 '15 at 11:00
1 Answers
3
Set third parameter to false and it works.
$('#toggleSwitchOn').click(function () {
$('#bootstrapswitch').bootstrapSwitch('state', true, false);
});

ankur140290
- 640
- 9
- 25
-
-
The method state can receive an optional third parameter skip. if true, switchChange event is not executed. The default is false. – ankur140290 Aug 12 '15 at 11:09
-
I need something else, $(this).bootstrapSwitch({ onSwitchChange: function(e, state) { if(state == false){ //do something }else{ //do something } } }); Also, I need to make the switch to be ON! – Raru Feb 28 '20 at 10:44