Skip to content

Instantly share code, notes, and snippets.

@benvinegar
Created December 3, 2010 22:21
Show Gist options
  • Save benvinegar/727646 to your computer and use it in GitHub Desktop.
Save benvinegar/727646 to your computer and use it in GitHub Desktop.
A helpful list of jQuery shortcuts + patterns
//--------------------------------------------------
// Get binary value of checkbox checked/not-checked
//--------------------------------------------------
// Seen often:
$('selector').attr('checked') ? 1 : 0;
// Alternatively:
Number($('selector').is(':checked'));
// More consise:
+$('selector').is(':checked');
//--------------------------------------------------
// Get value of checkbox if checked
//--------------------------------------------------
// Seen often:
$('selector').attr('checked') ? $(selector).val() : null;
// Alternatively:
$('selector:checked').val();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment