I wonder if it is possible to sum the values contained within the td using querySelectorAll? And show the result of the sum in span id="valor_total"
as shown in the code below.
function somaTds() {
var selecionados = [].slice.call(document.querySelectorAll('#tblEditavel vlr'));
var total = selecionados.reduce(function(soma, el) {
console.log(el.innerHTML);
return soma + Number(el.value);
}, 0);
document.getElementById('valor_total').innerHTML = total.toLocaleString('pt-br', {
minimumFractionDigits: 2,
currency: 'BRL'
});
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<table class="table table-condensed">
<tr>
<th>#</th>
<th>Nome</th>
<th>Valor</th>
</tr>
<tr>
<td>3</td>
<td>Casa</td>
<td class="vlr">R$ 200,00</td>
</tr>
<tr>
<td>89</td>
<td>Loja</td>
<td class="vlr">R$ 551,00</td>
</tr>
<tr>
<td colspan="2">Total</td>
<td><span id="valor_total">somando...</span></td>
</table>
<button class="btn btn-primary" name="btnSoma" onclick="somaTds()">Somar</button>
Clicking the Add button returns a value that is zeroed.