I have this sample code:
<table>
<tr>
<td class="price">1</td>
</tr>
<tr>
<td class="price">4</td>
</tr>
<tr>
<td class="price">6</td>
</tr>
</table>
<p id="setTotal"> </p>
I want to get the total of those values under class "price" however my output goes something like:
1 4 6 Sum is 0[object HTMLTableCellElement][object HTMLTableCellElement][object HTMLTableCellElement].
My JavaScript code is:
var arr = [];
var totalPrice = 0;
var i;
$("td.price").each(function(){
arr.push($(this).text());
totalPrice += this;
document.getElementById("setTotal").innerHTML = "Sum is "+totalPrice+ ".";
});