JSFiddle - React, Tailwind, and code Playground
by vigneshwaranr
HTML
<p>Foo</p>
<p>Bar</p>
<p></p>
JavaScript
(function($) {
$.fn.every = function(fn) {
for (var i = 0; i < this.length; i++) {
if (!!fn.call(this[i]) === false) {
return false;
}
}
return true;
};
$.fn.any = function(fn) {
for (var i = 0; i < this.length; i++) {
if (!!fn.call(this[i]) === true) {
return true;
}
}
return false;
};
})(jQuery);
//Check if every element is non-empty
var everyResult = $('p').every(function() {
return $(this).text().trim() != '';
});
//Check if any element has 'Bar' innerText
var anyResult = $('p').any(function() {
return this.innerText == 'Bar';
});
console.log("Every Result: " + everyResult);
console.log("Any Result: " + anyResult);