Fork me on GitHub

Bootstrap switch - by Mattia Larentis (@SpiritualGuru)

Size

<div class="switch switch-large">
    <input type="checkbox" checked />
</div>

<div class="switch">
    <input type="checkbox" checked />
</div>

<div class="switch switch-small">
    <input type="checkbox" checked />
</div>

<div class="switch switch-mini">
    <input type="checkbox" checked />
</div>

Colors

<div class="switch" data-on="primary" data-off="info">
    <input type="checkbox" checked />
</div>

<div class="switch" data-on="info" data-off="success">
    <input type="checkbox" checked />
</div>

<div class="switch" data-on="success" data-off="warning">
    <input type="checkbox" checked />
</div>

<div class="switch" data-on="warning" data-off="danger">
    <input type="checkbox" checked />
</div>

<div class="switch" data-on="danger" data-off="default">
    <input type="checkbox" checked />
</div>
<div class="switch" data-on="default" data-off="primary">
    <input type="checkbox" checked />
</div>

Animation

<div class="switch" data-animated="false">
    <input type="checkbox" checked />
</div>

Disabled

<div class="switch">
   <input type="checkbox" checked disabled />
</div>

Text

<div class="switch" data-on-label="SI" data-off-label="NO">
    <input type="checkbox" checked />
</div>

HTML text

<div class="switch" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
    <input type="checkbox" checked />
</div>

Event handler javascript

$('#mySwitch').on('switch-change', function (e, data) {
    var $el = $(data.el)
      , value = data.value;
    console.log(e, $el, value);
});

Toggle State javascript



Status!
ON!
Toggle me!
OFF!
$('#toggle-state-switch').bootstrapSwitch('status'); // true || false
$('#toggle-state-switch').bootstrapSwitch('toggleState');
$('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false

Destroy javascript



$('#destroy-switch').bootstrapSwitch('destroy');

Create javascript



Create
$('#create-switch').wrap('<div class="switch" />').parent().bootstrapSwitch();

Disabled javascript



$('#disable-switch').bootstrapSwitch('isActive');
$('#disable-switch').bootstrapSwitch('toggleActivation');
$('#disable-switch').bootstrapSwitch('setActive', false);  // true || false

Radio javascript

<div class="control-group">
    <div class="control-group">
        <label class="control-label" for="option1">Option 1</label>
        <div class="controls">
            <div id="option1" class="switch radio2">
                <input type="radio" name="radio2" value="option1" checked />
            </div>
        </div>
    </div>
    <div class="control-group">
        <div>
        <label class="control-label" for="option2">Option 2</label>
        </div>
        <div class="controls">
            <div id="option2" class="switch radio2">
                <input type="radio" name="radio2" value="option2" />
            </div>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="option3">Option 3</label>
        <div class="controls">
            <div id="option3" class="switch radio2">
                <input type="radio" name="radio2" value="option3" />
            </div>
        </div>
    </div>
</div>            
<script>
    $(document).ready(function() {
        $('.radio2').on('switch-change', function () {
            $('.radio2').bootstrapSwitch('toggleRadioState');
        });
    });
</script>

Form - try to use tab, space and reset button

<form class="form-horizontal">
    <div class="control-group">
        <label class="control-label" for="inputEmail">Email</label>
        <div class="controls">
            <input type="text" id="inputEmail" placeholder="Email">
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="notification1">Notification 1</label>
        <div class="controls">
            <div class="switch" tabindex="0">
                <input id="notification1" type="checkbox" />
            </div>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="notification2">Notification 2</label>
        <div class="controls">
            <div class="switch" tabindex="0">
                <input id="notification2" type="checkbox" />
            </div>
        </div>
    </div>
    <div class="form-actions">
        <button type="reset" class="btn btn-inverse">Reset</button>
    </div>
</form>

Modal

<a href="#myModal" role="button" class="btn" data-toggle="modal">Modal</a>
-----
<div class="modal-body">
    <div class="switch">
        <input type="checkbox" checked />
    </div>
</div>

follow me - my site