1
I cannot show the total price in your respective field.
let acum = 0
document.querySelectorAll("[td]").forEach(elemento => {
let valorComponente = () => elemento.textContent
let retiraVirgula = () => valorComponente.replace(",", ".")
let conversao = () => parseFloat(retiraVirgula)
acum = acum + retiraVirgula
document.querySelector("[tdTotal]").textContent = acum
})
table {
border-collapse: none;
}
td {
padding: 10px;
}
thead {
font-weight: bold;
background-color: rgb(27, 27, 27);
color: white;
}
tbody tr:hover {
background-color: rgb(155, 155, 155);
color: white;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Teste tabela</title>
</head>
<body>
<table border="1">
<caption>Registro Animais</caption>
<thead>
<tr>
<td>Nome</td>
<td>Raça</td>
<td>Peso</td>
<td>Latido</td>
<td>Preço</td>
</tr>
</thead>
<tbody>
<tr>
<td>Billy</td>
<td>Poodle</td>
<td>15kg</td>
<td>Fino</td>
<td td>400,00</td>
</tr>
<tr>
<td>Joke</td>
<td>pastor alemao</td>
<td>40kg</td>
<td>grosso</td>
<td td>2000,00</td>
</tr>
<tr>
<td>Jow</td>
<td>Poodle</td>
<td>22kg</td>
<td>Fino</td>
<td td>1400,00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">Total</td>
<td tdTotal></td>
</tr>
</tfoot>
</table>
</body>
</html>
Thanks for the reply, helped me understand the mistake.
– Alessander Júnio
@Alessanderjúnio If the answer solved your problem, you can accept it, see here how and why to do it. It is not mandatory, but it is a good practice of the site, to indicate to future visitors that it solved the problem
– hkotsubo