+ 1

How to calculate total of a table?

Look at this table. https://code.sololearn.com/W1e2gaCMCxpp/#css Daily expenses are not stable its must change everyday. If the value of price change it should automatically calculate the total. How I can do this with javascript?

24th Jul 2018, 4:50 AM
Nayem
2 Respostas
+ 2
function getTotal() { var prices = document.querySelectorAll("tbody tr td:nth-of-type(4)"); var total = document.querySelector("tfoot tr td:nth-of-type(4)"); var sum = 0; for(price of prices) sum += parseInt(price.innerText, 10); total.innerText = sum; } getTotal(); https://code.sololearn.com/WSLm3LY3MUj1/?ref=app
24th Jul 2018, 5:32 AM
Calviղ
Calviղ - avatar
+ 1
thanks
24th Jul 2018, 5:36 AM
Nayem