Dynamic Double Option Buttons With jQuery

File Size: 6.92 KB
Views Total: 196
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Dynamic Double Option Buttons With jQuery

A small jQuery plugin for creating customizable, dynamic double option buttons that trigger certain events when the left or right label is selected.

The goal of this plugin is to create inline left and right side buttons that can be used to replace the ugly checkbox or radio inputs.

How to use it:

1. Import the jQuery library, dbl-opt-style.css, and dbl-opt-style.js into the document.

<link rel="stylesheet" href="dbl-opt-style.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" 
<script src="dbl-option.js" ></script>

2. Create a containe in which you want to place the double option buttons.

<div class="option-container"></div>

3. Generate the double option buttons in the container element and do something as you like. Available event handlers:

  onRight: function () {
    // do something
  onLeft: function () {
    // do something
  onChange: function () {
    // do something

4. Customize the appearance of the double option buttons.


  // width
  width: '220px',

  // height
  height: '30px',
  // text for left button
  leftLabel: 'OPTION 1',

  // text for right button
  rightLabel: 'OPTION 2',

  // enables animation
  animation: true,
  // background color of selected button
  bgSelector: '#363b44'


5. Set the initial button.


  // default: right
  initSide: 'left'


6. Decide whether to trigger the events on inti.


  // default: true
  callOnInit: false


7. Set the side manually.


8. Toggle the side manually.


9. Get the current side.


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