25

I am using http://bootstrapswitch.site/ for toggle switch buttons. How can I get the toggle switch like 'on' or 'off' using jQuery?

My Code is :

<div class="make-switch  switch-small"><input type="radio" class="nsfw"></div>

Please tell me how to solve this issue.

0

4 Answers 4

66
$('#switcher').bootstrapSwitch('state'); // true || false
$('#switcher').bootstrapSwitch('toggleState');

Refer this link for more functions

4
  • 2
    $('#switcher').bootstrapSwitch('state'); Jun 21, 2014 at 17:27
  • 1
    Why $('#switcher').bootstrapSwitch('state'); will overide the existing widget?
    – JaskeyLam
    Apr 20, 2015 at 7:17
  • @janhartmann seems an update have been done, so $('#switcher').bootstrapSwitch('setState', false); does not work anymore, should be $('#switcher').bootstrapSwitch('state', false); May 15, 2017 at 14:50
  • Fixed @DanielH :-) May 16, 2017 at 3:30
17

As far as I can tell the method has been updated (but not well documented).

$('#switcher').bootstrapSwitch('state', true)
$('#switcher').bootstrapSwitch('state', false)
2
  • 1
    weird, the documentation is still not updated! Thanks for the tip!
    – Anupam
    Nov 5, 2016 at 8:01
  • this one works for me, thanks! (seems like an update) May 15, 2017 at 14:49
3

About changing state in my case,

('#switcher').bootstrapSwitch('state', false); 

It's correct code.

1
$('#switcher').bootstrapSwitch('state');

Not work for me, but in my version:

$("#switcher").bootstrapSwitch("status");

can work well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.