I want to ask if there\'s a better way in jQuery to select multiple text input then check if any of them has a value. Here\'s my code:
if ($(\"#reference\")
The problem with getting the length property on filter() is that jQuery will evaluate every single element in the collection, just to populate a count when all we care about is whether the value is greater than zero.
None of the current answers and even jQuery's own .is(), .has(), and .filter() make use of short circuiting as soon as the criteria is met.
You can define a simple extension method called .any() like this:
jQuery.fn.any = function(filter){
for (i=0 ; i
And then pass in a filtering function like this:
var someInputsEmpty = $("#reference,#pin,#fName,#mName,#datepicker").any(function() {
return this.value == '';
});
jQuery.fn.any = function(filter){
for (i=0 ; i