-
-
Save evdokimovm/08f34089f0d032f2d7364fc1de9d70da to your computer and use it in GitHub Desktop.
jQuery plugin for shift + click to select multiple checkboxes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: $form.find('input[type="checkbox"]').shiftSelectable(); | |
// replace input[type="checkbox"] with the selector to match your list of checkboxes | |
$.fn.shiftSelectable = function() { | |
var lastChecked, | |
$boxes = this; | |
$boxes.click(function(evt) { | |
if(!lastChecked) { | |
lastChecked = this; | |
return; | |
} | |
if(evt.shiftKey) { | |
var start = $boxes.index(this), | |
end = $boxes.index(lastChecked); | |
$boxes.slice(Math.min(start, end), Math.max(start, end) + 1) | |
.attr('checked', lastChecked.checked) | |
.trigger('change'); | |
} | |
lastChecked = this; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment