Skip to content

Instantly share code, notes, and snippets.

@Lotuashvili
Created March 25, 2015 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lotuashvili/0fc6d53068503fce34c0 to your computer and use it in GitHub Desktop.
Save Lotuashvili/0fc6d53068503fce34c0 to your computer and use it in GitHub Desktop.
Chech/Uncheck all checkboxes with coffeescript
$('.list .checkAll').change ->
status = this.checked
boxes = $('.list input[type="checkbox"]:not(.checkAll)')
boxes.each (i, elem) =>
elem.checked = status
return
$('.list input[type="checkbox"]:not(.checkAll)').change ->
num = $('.list input[type="checkbox"]:not(.checkAll)').filter(':not(:checked)').length # shows not checked num
if num == 0
$('.list .checkAll')[0].checked = true
else if num > 0
$('.list .checkAll')[0].checked = false
num2 = $('.list input[type="checkbox"]:not(.checkAll)').filter(':checked').length # shows checked num
if num2 == 0
deleteAllDisable() # To disable "delete all" button
else if num2 > 0
deleteAllEnable() # To enable "delete all" button
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment