2 * jQuery checkboxShiftClick
4 * This will enable checkboxes to be checked or unchecked in a row by clicking one,
5 * holding shift and clicking another one.
7 * @author Timo Tijhof, 2011 - 2012
11 $.fn.checkboxShiftClick = function () {
12 var prevCheckbox = null,
14 // When our boxes are clicked..
15 $box.click( function ( e ) {
16 // And one has been clicked before...
17 if ( prevCheckbox !== null && e.shiftKey ) {
18 // Check or uncheck this one and all in-between checkboxes,
19 // except for disabled ones
22 Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ),
23 Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1
25 .filter( function () {
26 return !this.disabled;
28 .prop( 'checked', !!e.target.checked );
30 // Either way, update the prevCheckbox variable to the one clicked now
31 prevCheckbox = e.target;