Toggle Switch is a lightweight jQuery plugin which creates tiny and easy to use toggle buttons.
Toggle Switch is a lightweight jQuery plugin which creates tiny and easy to use toggle buttons.
It is a visual element which can be a replacement for standard HTML checkboxes.
Simply run the script and your site will be updated with these specialized controls. Best of all, the underlying checkbox is not touched and backend system will never know the difference. The change is purely visual.
The plugin is image free which means that the download size is quite small.
/* Attach the Toggle Switch CSS file */
<link rel=" stylesheet" type="text/css" href="css/tinytools.toggleswitch.min.css">
/* jQuery needs to be attached */
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
/* Then attach the Toggle SWitch plugin */
<script src="tinytools.toggleswitch.min.js"></script>
<input type="checkbox" id="ToggleSwitchSample" />
<script>
$(document).ready(function () {
$("#ToggleSwitchSample").toggleSwitch();
});
</script>
Property | Default | Description |
---|---|---|
width | "100px" | The width of the toggle switch. |
height | "20px" | The height of the toggle switch. |
onLabel | ON | The text of the "ON" state. |
offLabel | OFF | The text of the "OFF" state. |
onToggle | false | callback that fires after changeing the state of the toggle switch. Parameters: 1- Check state, 2- Caller. Alternatively, you can use the default onChange event of the underlying checkbox. |
Method | Description |
---|---|
$(selector).toggleCheckedState(value) |
On or off the selected toggle switch(es). The value parameter can be true or false.
It also changes the underlying checkbox checked value.
Alternatively, you can change the underlying checked value using the $(selector).prop('chacked', '<value>');
Notice: The $(selector).attr('chacked', '<value>'); will not work properly. |