Skip to content

Instantly share code, notes, and snippets.

@KeithP
Created August 6, 2014 12:47
Show Gist options
  • Save KeithP/300bdd9de2237ea0fbf9 to your computer and use it in GitHub Desktop.
Save KeithP/300bdd9de2237ea0fbf9 to your computer and use it in GitHub Desktop.
jQuery CoffeeScript for shift + click to select multiple checkboxes
lastSelected = null
checkboxHead = $( "thead :checkbox" )
checkboxes = $( "tbody :checkbox" )
checkboxHead.click (e) ->
isChecked = this.checked
checkboxes.each ->
$(this).prop( "checked", isChecked )
checkboxes.click (e) ->
thisSelected = checkboxes.index( this )
isChecked = this.checked
if e.shiftKey && thisSelected != lastSelected
checkboxes.slice( Math.min( lastSelected, thisSelected ), Math.max( lastSelected, thisSelected ) + 1).each ->
$(this).prop( "checked", isChecked )
lastSelected = thisSelected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment