iterate trough each selecter jquery
Posted
by Sam Vloeberghs
on Stack Overflow
See other posts from Stack Overflow
or by Sam Vloeberghs
Published on 2010-03-20T15:57:16Z
Indexed on
2010/03/20
16:01 UTC
Read the original article
Hit count: 338
Hi
I'm having problems calculating stuff on my web app. Here is the scenario:
I have a html markup like this:
<table>
<tr>
<td><span class="sub_total">10</span></td>
</tr>
<tr>
<td><span class="sub_total">10</span></td>
</tr>
<tr>
<td><span class="sub_total">10</span></td>
</tr>
</table>
<p><span id="total"></span></p>
I would like to calculate the main total of all the sub totals:
var total;
$('.sub_total').each(function(){
total = total + parseInt($(this).text());
});
$('#total').text(total);
But I can't get this to work. I get a NaN notification..
Plz help and advice
Greeting
© Stack Overflow or respective owner