Skip to content

Instantly share code, notes, and snippets.

@justinrains
Created June 14, 2011 21:30
Show Gist options
  • Save justinrains/1025948 to your computer and use it in GitHub Desktop.
Save justinrains/1025948 to your computer and use it in GitHub Desktop.
Checkbox toggle
/*
* jQuery - toggle checkboxes
* June 14, 2011 - Justin Rains
* http://www.justinrains.com/
*
* Dual licensed under 'Use it like you stole it'
* and 'I Don't Care'.
* Description: Toggle checkboxes. Get creative and put them on a timer! Fun!
* Example usage:
* $(':checkbox').cbToggle();
* OR
* $('.cbt :checkbox').cbToggle(); // this will toggle all checkboxes in the .cbt class div, p, span, etc
*
* Enjoy!
*/
$.fn.cbToggle = function() {
this.each(function() {
$(this).prop('checked', ($(this).prop('checked')) ? false : true);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment