There are some minor optimization issues unaddressed by the existing answers, so I'll throw my hat in the ring with what I believe is the most readable/performant code.
Add a jQuery extension method like this which will short circuit :
<!-- language: lang-js -->
/**
* Determines whether all elements of a sequence satisfy a condition.
* @@param {function} predicate - A function to test each element for a condition.
* @@return {boolean} true if every element of the source sequence passes the test in the specified predicate
*/
$.fn.all = function (predicate) {
$(this).each(function (i, el) {
if (!predicate.call(this, i, el)) return false;
});
// we made it this far, we're good.
return true;
};
Then call it like this:
<!-- language: lang-js -->
var allValid = $("form :input").all(function () {
return $(this).valid();
});