JSFiddle - React, Tailwind, and code Playground
by Matthew Adams
HTML
<table id="hours" border="1">
<tbody>
<tr>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
<td>0</td>
<td>0.0</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>24</td>
<td>1</td>
<td>7</td>
<td>2</td>
<td>4</td>
<td>0</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
<td>0</td>
<td>0.0</td>
</tr>
<tr>
<td>24</td>
<td>1</td>
<td>7</td>
<td>2</td>
<td>4</td>
<td>0</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
<td>0.0</td>
<td>0</td>
<td>0.0</td>
</tr>
</tbody>
</table>
JavaScript
$(document).ready(function () {
$('td').click(function () {
var col = $(this).parent().children().index($(this));
var row = $(this).parent().parent().children().index($(this).parent());
console.log('Row: ' + row + ', Column: ' + col);
var val1 = 0;
var val2 = 0;
var t = document.getElementById('hours');
for (i = 1; i < row; i++) {
var val1 = $(t.rows[i].cells[col]).text();
console.log('Row: ' + i + ', Column: ' + col);
console.log($('#hours tr:eq(' + i + ') td:eq(' + col + ')').text);
val2 += Number(val1);
}
});
});