jQuery Button Switch

A simple way to create button switches

View On GitHub

Install


npm install jquery-btnswitch

you must be using at least jQuery 2.0

Settings


Examples


Basic Implementation


$('#btnSwitch').btnSwitch();

Confirm Action with Callback


$('#btnSwitch').btnSwitch({
    ConfirmChanges: true,
    ConfirmText: 'You really want to do that?',
    OnCallback: function(val) {
        alert('system is now on');
    },
    OffCallback: function (val) {
        alert('system is now off');
    }
});

Callback


$('#btnSwitch').btnSwitch({
    OnValue: 'On',
    OnCallback: function(val) {
        alert('you selected ' + val);
    },
    OffValue: 'Off',
    OffCallback: function (val) {
        alert('you selected ' + val);
    }
});

Themes


You can change the look of the switch by selecting one of the possible themes below:

Light


$('#btnSwitch').btnSwitch({
    Theme: 'Light'
});

Swipe


$('#btnSwitch').btnSwitch({
    Theme: 'Swipe'
});

iOS


$('#btnSwitch').btnSwitch({
    Theme: 'iOS'
});

Android


$('#btnSwitch').btnSwitch({
    Theme: 'Android'
});