Last active
December 19, 2015 10:28
-
-
Save rubygeek/5940182 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(function( $ ){ | |
$.fn.blank = function() { | |
return $(this).val() == "" | |
}; | |
})( jQuery ); | |
Usage | |
if ($("#old_password").blank()) { | |
console.log("old passworld is blank"); | |
} | |
Better use | |
$("#old_password").is(":blank") | |
if you dont have :blank available to your version of jquery (I didn't have it in 1.6) add it like this: | |
$.extend($.expr[':'],{ | |
blank: function(element) { | |
return $.trim($(element).val()) === ''; | |
} | |
}); | |
Thanks to @ethangarofolo for reminding me to use threequals | |
Thanks to @tehviking for suggestion of trim | |
Thanks to @cowboyd and the link to http://james.padolsey.com/javascript/extending-jquerys-selector-capabilities/ to create the custom selector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment