I’m looking to sum up all text as numbers inside the class called “sent” but when I alert the below code it gives output of zero:
var sum = 0;
var thedate = $(".date:contains('15th February 2012')");
$(thedate).each(function() {
var sents = $(this).next('.sent').text();
var sentsnumb = parseFloat(sents);
sum += Number($(sentsnumb));
});
alert(sum);
Here is my html:
<tr>
<td class="date">15th February 2012</td>
<td class="sent"> 5</td>
</tr>
<tr>
<td class="date">15th February 2012</td>
<td class="sent"> 5</td>
</tr>
<tr>
<td class="date">15th February 2012</td>
<td class="sent"> 10</td>
</tr>
<tr>
<td class="date">15th February 2012</td>
<td class="sent"> 10</td>
</tr>
Desired output from above would be the number “30”.
Try this way:-
Actual problem is with $(sentsnumb). It should be replaced with sentsnumb