Created
December 3, 2010 22:21
-
-
Save benvinegar/727646 to your computer and use it in GitHub Desktop.
A helpful list of jQuery shortcuts + patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------- | |
// 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