I have a table head <th>
that is set by default to 0
:
<th id="total_price" style="text-align:center">0</th>
Now when, I add a new sold item, the price should be added to the value of the this <th>
. So, if the new one is 20000, the value should be 20000+0=20000
and not 200000
. And if I add another item, with price of 30 000 it would be now like 20000030 000
.
This is jquery script:
var initial = $("#total_price").text();
console.log(initial);
var newPrice = initial + (res['price']);
console.log(newPrice);
$("#total_price").text(newPrice);
I tried this:
var initial = $("#total_price").text();
console.log(initial);
var newPrice = initial + +(res['price']);
console.log(newPrice);
$("#total_price").text(newPrice);
But still the same.