$.fn.rangeSelect = function() { var lastCheckbox = null; var $spec = this; $spec.bind("click", function(e) { if (lastCheckbox != null && e.shiftKey) { $spec.slice( Math.min($spec.index(lastCheckbox), $spec.index(e.target)), Math.max($spec.index(lastCheckbox), $spec.index(e.target)) + 1 ).attr({checked: e.target.checked ? "checked" : ""}); } lastCheckbox = e.target; }); return $spec; };