JSFiddle - React, Tailwind, and code Playground
by dmethvin
HTML
<html>
<body>
<input name="Red" class="color"/>
<input name="Blue" class="color"/>
<input name="Green" class="color"/>
</body>
</html>
JavaScript
// #8689 - .collect() is .map()
(function($) {
$.fn.collect = function(callback) {
if (typeof(callback) == "function") {
var collection = [];
$(this).each(function() {
var item = callback.apply(this);
if (item)
collection.push(item);
});
return collection;
}
return this;
}
})(jQuery);
var inputs = $("input.color").filter(function(){return true;});
alert("This is what returned by filter: " + inputs);
var colors = $("input.color").collect(function(){return this.name;});
alert("This is what returned by collect: " + colors);
var colors2 = $("input.color").map(function(){return this.name;}).get();
alert("This is what returned by collect: " + colors2);