jQuery CheckThemAll

A light-weight plugin to create checkbox lists with an "all" choice.

Get on Github

Minimalist

Does one thing, and does it right.

Event Based

Multiple callbacks are available at every step of the way, allowing you to plug your business logic into the plugin.

Cross Browser

CheckThemAll is compatible with all modern browsers, starting from IE7.

In most cases, you won't need extra configuration for CheckThemAll to work properly. In some cases though, you might need to change the default parameters to meet your specific needs. There are two ways to set parameters:

Let's take an example with the masterCheckboxClass parameter (described below), you can set it either in your container element:

<div id="checkbox_container" data-checkthemall-mastercheckboxclass="some-class">
  ...
</div>

Or when instantiating the plugin:

$('.checkthemall').checkThemAll({
  masterCheckboxClass: 'some-class'
});

Here is the full (but short) list of available parameters, along with their default values. To use them as data- attributes, simply prefix with data-checkthemall-

Note Parameters expecting functions cannot be used as data- attributes.

defaults = {
  masterCheckboxClass: 'master-checkbox',
  slaveCheckboxClass: 'slave-checkbox',
  onCheckBefore: function() { return; },
  onCheckAfter: function() { return; },
  onUncheckBefore: function() { return; },
  onUncheckAfter: function() { return; },
  onMasterCheckBefore: function() { return; },
  onMasterCheckAfter: function() { return; },
  onMasterUncheckBefore: function() { return; },
  onMasterUncheckAfter: function() { return; },
  onSlaveCheckBefore: function() { return; },
  onSlaveCheckAfter: function() { return; },
  onSlaveUncheckBefore: function() { return; },
  onSlaveUncheckAfter: function() { return; },
}

You can hook to pre and post checking events to perform certain tasks.

Hooks receive 3 parameters :

Available hooks are :

Basic Usage

Example 1: Nothing checked on page load

Example 2: "All" checked on page load

Example 3: "Choice 1" and "Choice 3" checked on page load

Example 4: All choices checked on page load - the plugin unchecks them all, and checks the "All" checkbox instead.

Example 5: Radio button instead of checkbox

Hooks

Example: Click the checkboxes to see the hooks in action.

Example: Disabling slaves when master is checked.