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.

Reply via email to