Is there any easy way to check if any elements in a jquery selector fulfill a condition? For instance, to check if any textboxes in a form are empty (kind o
.is() with a function argument is what you're after.
var anyEmpty = $('input.tb').is(function(index, element) {
return !element.value;
})
WARNING:
This function is surprising in that it doesn't short circuit. It will needlessly iterate through all selected elements, even if the callback has already been satisfied.
let i = 0
let result = $('div').is((index, element) => {
i++;
return element.tagName === 'DIV';
})
console.log(`count = ${i}, result = ${result}`);
// count = 732, result = true