Switch

Visual

image-switch
image-switch

A simple on/off switch made from a button. This element provides functionality to change the switch and get the current state.

Data type

<button id="my-switch" data-type="dizmo-switch"></button>

Constraints

Only works on button elements.

Usage

Manual initialization:

DizmoElements('#my-switch').dswitch();

To change the state of the button programmatically, call ‘state’. The same function is also used to get the current state.

DizmoElements('#my-switch').dswitch('state', 'off');
DizmoElements('#my-switch').dswitch('state', 'on');

To get the current state:

var state = DizmoElements('#my-switch').dswitch('state');

To react to state changes:

DizmoElements('#my-switch').on('click',function(){
    var state = DizmoElements('#my-switch').dswitch('state');
});