Thomas, I also have a calculation plug-in I've been working on that does just want you want:
http://www.pengoworks.com/workshop/jquery/calculation.plugin.htm $(".number").sum(); My plug-in also handles numbers that have addition formatting in them by using a RegEx to parse the numbers out (which is a configuration option that can be changed.) -Dan >-----Original Message----- >From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On >Behalf Of Gordon >Sent: Thursday, August 30, 2007 9:31 AM >To: jQuery (English) >Subject: [jQuery] Re: simple math: add all values of (span class="number") >and output result > > >Just hammered together in a few seconds as I typed, might not work > >var runningTotal = 0; > >$('.number').each (function () >{ > runningTotal += ($(this).html () * 1); // The multiply forces a >typecast from string to a number type >}); > >$('.result').html (runningTotal); > >On Aug 30, 12:09 am, bytte <[EMAIL PROTECTED]> wrote: >> I want to do some simple math. I want to collect all numbers that are >> in a span with the class "number" and add them to each other. Then >> output the result in another span (id="result"). >> >> <span class="number">25</span> >> <span class="number">25</span> >> <span class="number">25.5</span> >> >> So this should be the result: >> <span id="result">75.5</span> >> >> I know it's simple, but I don't know the syntax to add the numbers. >> Can you help me out or give me a hint in the right direction? It's >> probably just a one line script looping through the spans and adding >> them. >