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
20 Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ),
21 Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1
22 ).prop( 'checked', !!e.target.checked );
24 // Either way, update the prevCheckbox variable to the one clicked now
25 prevCheckbox = e.target;