A jQuery plugin which allows you to quickly add check all/uncheck all functionality to your forms or tables.
< check all here | |
---|---|
Bender | |
Fry | |
Dr. Zoidberg | |
Professor Farnsworth |
Download the latest release v.0.5.0 (tar.gz) (zip). Source is also available on GitHub.
Include jQuery and the script somewhere on your page.
<script src="jquery.js"></script> <script src="jquery-check-all.js"></script>
You’ll have markup which contains your checkboxes, for example:
<table> <thead> <tr> <td><input id="check-all" type="checkbox"></td> <td></td> </tr> </thead> <tbody> <tr> <td><input type="checkbox" value="1"></td> <td>option 1</td> </tr> <tr> <td><input type="checkbox" value="2"></td> <td>option 2</td> </tr> <tr> <td><input type="checkbox" value="3"></td> <td>option 3</td> </tr> </tbody> </table>
Call the checkAll()
function on your “check all” checkbox to initialize the plugin.
<script> $(document).ready(function() { $('#check-all').checkAll(); }); </script>
The plugin can be supplied with an options object to further filter which checkboxes you want to group.
var options = { container: $('#table'), showIndeterminate: true }; $('#check-all-box').checkAll(options);
Alternatively, options may be supplied via data attributes. Note that options passed via the options object will override any options specified via data attributes.
<input id="check-all" type="checkbox" data-show-indeterminate="true">
Available options:
document
.input[type=checkbox]
. Note: if you supply this option, make sure what you’re passing are checkboxes.Released under the MIT License.