Skip to main content

Bug Tracker

Side navigation

#1356 closed feature (wontfix)

Opened July 05, 2007 03:57AM UTC

Closed November 14, 2007 03:33AM UTC

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:
Description

<div>1</div>

<div>3</div>

<div>6</div>

jQuery Code:

$("div").sum(); //returns 10

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

Attachments (0)
Change History (1)

Changed November 14, 2007 03:33AM UTC by brandon comment:1

priority: majorminor
resolution: → wontfix
status: newclosed

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;
};