TL;DR — A jQuery plugin that gives you nice powers over your checkboxes.
JavaScript
jQuery(function($) {
$('#btn-check-all').on('click', function(e) {
$('#table1').checkboxes('check');
e.preventDefault();
});
});
Data API
The following snippet is the equivalent form of the previous JavaScipt code rewritten with the data API.
<a href="#table1"
data-toggle="checkboxes"
data-action="check">Check all</a>
This will have the exact same effect as the JavaScript code.
JavaScript
jQuery(function($) {
$('#btn-uncheck-all').on('click', function(e) {
$('#table2').checkboxes('uncheck');
e.preventDefault();
});
});
Data API
The following snippet is the equivalent form of the previous JavaScipt code rewritten with the data API.
<a href="#table2"
data-toggle="checkboxes"
data-action="uncheck">Uncheck all</a>
This will have the exact same effect as the JavaScript code.
Results
#table2 |
---|
JavaScript
jQuery(function($) {
$('#btn-toggle').on('click', function(e) {
$('#table3').checkboxes('toggle');
e.preventDefault();
});
});
Data API
The following snippet is the equivalent form of the previous JavaScipt code rewritten with the data API.
<a href="#table3"
data-toggle="checkboxes"
data-action="toggle">Toggle all</a>
This will have the exact same effect as the JavaScript code.
Results
#table3 |
---|
Range selection is a feature that allow checking a range of checkboxes by checking the first checkbox as the starting point, then while pressing the SHIFT
key checking another checkbox that will be the ending of the range, and all checkboxes between will be checked.
JavaScript
jQuery(function($) {
$('#table4').checkboxes('range', true);
});
Data API
The following snippet is the equivalent form of the previous JavaScipt code rewritten with the data API.
<div data-toggle="checkboxes"
data-range="true">
...
<-- set of checkboxes -->
...
</div>
This will have the exact same effect as the JavaScript code.
Results
#table4 |
---|
Often, it is useful to limit the number of checkboxes that can be checked within a context.
JavaScript
jQuery(function($) {
$('#table5').checkboxes('max', 3);
});
Data API
The following snippet is the equivalent form of the previous JavaScipt code rewritten with the data API.
<div data-toggle="checkboxes"
data-max="3">
...
<-- set of checkboxes -->
...
</div>
This will have the exact same effect as the JavaScript code.
Results
#table5 |
---|