Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <h3>jQuery Checkbox Buttons<br />
    <small>Buttons that change the state of their own hidden checkboxes, and vice-versa!<br>
      Source: <a>https://bootsnipp.com/snippets/featured/jquery-checkbox-buttons</a>
    </small>
  </h3>
  
  <hr>
  
  <br>
  
  <div class="input-group col-md-4">
    <span class="button-checkbox input-group-btn">
      <button type="button" class="btn" data-color="primary">Option One</button>
      <input type="checkbox" class="hidden" checked />
    </span>
    <span class="button-checkbox input-group-btn">
      <button type="button" class="btn" data-color="primary">Option Two</button>
      <input type="checkbox" class="hidden" />
    </span>
    <span class="button-checkbox input-group-btn">
      <input type="checkbox" class="hidden" checked />
      <button type="button" class="btn" data-color="primary">Option Three</button>
    </span>
  </div>
              
            
!

CSS

              
                *:focus {
  outline: none !important;
}

.input-group-btn .btn {
  width: 100%;
}

:not(:first-child):not(:last-child).input-group-btn.button-checkbox .btn {
  border-radius: 0px;
}
              
            
!

JS

              
                $(function () {
  $('.button-checkbox').each(function () {

    // Settings
    var $widget = $(this),
        $button = $widget.find('button'),
        $checkbox = $widget.find('input:checkbox'),
        color = $button.data('color'),
        settings = {
          on: {
            icon: ''//'glyphicon glyphicon-check'
          },
          off: {
            icon: ''//'glyphicon glyphicon-unchecked'
          }
        };

    // Event Handlers
    $button.on('click', function () {
      $checkbox.prop('checked', !$checkbox.is(':checked'));
      $checkbox.triggerHandler('change');
      updateDisplay();
    });
    $checkbox.on('change', function () {
      updateDisplay();
    });

    // Actions
    function updateDisplay() {
      var isChecked = $checkbox.is(':checked');

      // Set the button's state
      $button.data('state', (isChecked) ? "on" : "off");

      // Set the button's icon
      $button.find('.state-icon')
        .removeClass()
        .addClass('state-icon ' + settings[$button.data('state')].icon);

      // Update the button's color
      if (isChecked) {
        $button
          .removeClass('btn-default')
          .addClass('btn-' + color + ' active');
      }
      else {
        $button
          .removeClass('btn-' + color + ' active')
          .addClass('btn-default');
      }
    }

    // Initialization
    function init() {

      updateDisplay();

      // Inject the icon if applicable
      if ($button.find('.state-icon').length == 0) {
        $button.prepend('<i class="state-icon ' + settings[$button.data('state')].icon + '"></i> ');
      }
    }
    init();
  });
});
              
            
!
999px

Console