Modify ↓
Ticket #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: | |
| Blocking: | Blocked by: |
Description
<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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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