Simple, simple implementation:
$.fn.some = function(callback) {
var result = false;
this.each(function(index, element) {
if(callback.call(this, index, element)) {
result = true;
return false;
}
});
return result;
};
$.fn.every = function(callback) {
var result = true;
this.each(function(index, element) {
if(!callback.call(this, index, element)) {
result = false;
return false;
}
});
return result;
};
With ES5, arrays already provide methods everyand someso you can achieve the same with built-in methods:
okay = $("#myForm input").get().every(function(element) {
return $(element).val().length > 0
});
but it will not work in old version of IE without HTML5 shim .
source
share