This is my HTML table, on the table I have 3 rows and 3 columns, what I am trying to do is add the first two columns together and put the result in the third column. Any help would be greatly appreciated.
CSS:
<style type="text/css">
.tg { border-collapse:collapse; border-spacing:0; border-color:#bbb; }
.tg td { font-family:Arial, sans-serif; font-size:14px; padding:10px 5px;border-
style:solid; border-width:0px; overflow:hidden; word-break:normal; border-
color:#bbb; color:#594F4F; background-color:#E0FFEB; }
.tg th { font-family:Arial, sans-serif; font-size:14px; font-
weight:normal; padding:10px 5px; border-style:solid; border-
width:0px; overflow:hidden; word-break:normal; border-
color:#bbb; color:#493F3F; background-color:#9DE0AD; }
.tg .tg-jf1j { font-weight:bold; font-size:20px; color:#ffccc9; text-
align:center; vertical-align:top; }
.tg .tg-yw4l { vertical-align:top; }
</style>
HTML:
<table class="tg">
<tr>
<th class="tg-yw4l">1</th>
<th class="tg-yw4l">1</th>
<th id="a"></th>
</tr>
<tr>
<td class="tg-yw4l">1</td>
<td class="tg-yw4l">2</td>
<td id="a"></td>
</tr>
<tr>
<td class="tg-yw4l">2</td>
<td class="tg-yw4l">3</td>
<td id="a"></td>
</tr>
</table>
Below here is where I try looping through my table and adding the first two columns together.
<script type="text/javascript">
var table = document.getElementsByClassName("tg");
for (var r = 0; r < 3; r++) {
var sum1 = 0;
for (var c = 0; c < 3; r++) {
if (table[r][c].className == 'tg-yw41') {
sum1 += isNaN(table[r][c].innerHTML) ? 0 : parseInt(table[r][c].innerHTML);
}
}
document.getElementById('a').innerHTML = sum1;
}
</script>