Create Multi-state Switches From Buttons - jQuery stateButton

File Size: 3.56 KB
Views Total: 1883
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Create Multi-state Switches From Buttons - jQuery stateButton

The stateButton jQuery plugin creates a customizable multi-state toggle button which allows the user to switch between states on click. Ideal for collapse/expand buttons, ladda buttons(inline loading indicators) and more.

How to use it:

1. Insert the JavaScript file jquery.stateButton.js and we're ready to go.

<script src="" 
<script src="jquery.stateButton.js"></script>

2. Create a standard button for the toggle switch.

<button id="toggle">Click Me</button>

3. Active the toggle button which switches between collapse/expand states when clicked (Ideal for multi-level tree view).

  values: [ "Expanded", "Collapsed" ],
  current: "Collapsed"

4. Customize the button text and tooltip content.

  values: [ "Expanded", "Collapsed" ],
  current: "Collapsed",
  text: {
    "expanded" : "Collapse",
    "collapsed": "Expand"
  tooltip: {
    "expanded" : "Collapse all",
    "collapsed": "Expand all"

5. Add additional CSS classes to the toggle button.

  styleClass: {
    "expanded" : "btn-expanded",
    "collapsed": "btn-collapsed"
  inlineStyle: {
    "expanded": {
      "color": "red"
    "collapsed": {
      "color": "green"

6. Execute a callback function when you click the toggle button.

  clickCallback: function(newState, oldState) {
    console.log('button', this);
    console.log('old state', oldState);
    console.log('new state', newState);

7. You can also config the toggle buttons via data-OPTION attributes. Great for multiple toggle buttons on the page.

<button id="toggle"

This awesome jQuery plugin is developed by aprofetb. For more Advanced Usages, please check the demo page or visit the official website.