Skip to content

Instantly share code, notes, and snippets.

@rubygeek
Last active December 19, 2015 10:28
Show Gist options
  • Save rubygeek/5940182 to your computer and use it in GitHub Desktop.
Save rubygeek/5940182 to your computer and use it in GitHub Desktop.
(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