Bug Tracker

Opened 8 years ago

Closed 8 years ago

#1356 closed feature (wontfix)

May add a sum() function ?

Reported by: Heflying Owned by:
Priority: minor Milestone: 1.1.4
Component: core Version: 1.1.3
Keywords: function sum Cc:
Blocked by: Blocking:


<div>1</div> <div>3</div> <div>6</div>

jQuery Code: $("div").sum(); returns 10

it's useful (like XSLT's sum() function)

Change History (1)

comment:1 Changed 8 years ago by brandon

  • Priority changed from major to minor
  • Resolution set to wontfix
  • Status changed from new to closed

This will be best served as a plugin. The plugin code might look something like this (untested).

$.fn.sum = function() {
    var sum = 0;
    this.each(function() {
        sum += parseInt(this.innerText) || 0;
    return sum;
Note: See TracTickets for help on using tickets.