'Get number value from td innerText
This is my table:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Documento senza titolo</title>
<link href="Champions%20League/Champion%20League.css" rel="stylesheet" type="text/css">
</head>
<body style="border-style: none; border-collapse: collapse; empty-cells: show; table-layout: auto; font-family:Verdana, 'Hoefler Text', 'Liberation Serif', Times, 'Times New Roman', serif">
<table ;="" style="width: 80%; text-align: center; margin-left: auto; margin-right: auto;"
id="db" cellspacing="2" cellpadding="2" border="1">
<tbody>
<tr>
<td width="10%">09-11-1996</td>
<td width="10%">Norimberga</td>
<td style="text-align: right;" width="15%">Germania</td>
<td width="10%">3-0</td>
<td style="text-align: left;" width="15%">Irlanda del Nord</td>
<td width="25%">Qualificazioni Mondiali 1998 </td>
<td width="5%"><strong>1</strong></td>
</tr>
</tbody>
</table>
<script>
function GetCellValues() {
var table = document.getElementById('db');
var total = 0
for (var r = 0, n = table.rows.length; r < n; r++) {
total += parseInt(table.rows[r].cells[7].innerText)
}
alert(total);
}
GetCellValues()
</script>
</body>
</html>
The script at the end should repeat for a certain number of rows. But I can't extrapolate the numeric value present in the last cell (in this case, 1), since the final value of the total variable is NaN.
How can I fix it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
