jQuery: IsNullOrEmpty plugin for jQuery
I was a bit disappointed when couldn’t find in jQuery library a method similar to String.IsNullOrEmpty from C#. So, below is a simple jQuery plugin to examine whether the passed string is empty or null.
(function ($) {
$.isNullOrEmpty = function (str) {
return !str || $.trim(str) === ""; // the trim method is provided by jQuery
};
})(jQuery);
Some samples of use
var res = $.isNullOrEmpty(''); // true
res = $.isNullOrEmpty("bla-bla-bla"); // false
res = $.isNullOrEmpty(null); // true
res = $.isNullOrEmpty(); // true