Home > Article > Web Front-end > jQuery aggregate function example_jquery
The examples in this article describe jQuery aggregate functions. Share it with everyone for your reference. The details are as follows:
(function($) { $.fn.aggregate = function(seed, func) { var _r = seed == null ? "" : seed; this.each(function(index, element) { _r = func(_r, element); }); return _r; }; $.fn.count = function() { return this.aggregate( 0, // seed function(result, _) { // func return result + 1; }); }; })(jQuery); alert($("a").count());
I hope this article will be helpful to everyone’s jQuery programming.