I'm trying to generate a table with 3 rows and 3 cells e.g.
<table>
<tr>
<td> 00 </td> <td> 01 </td> <td> 02 </td>
</tr>
<tr>
<td> 10 </td> <td> 11 </td> <td> 12 </td>
</tr>
<tr>
<td> 20 </td> <td> 21 </td> <td> 22 </td>
</tr>
</table>
The Javascript I'm using to do this is:
tab = document.getElementById('tab');
for(i=0; i<3; i++)
{
tab.innerHTML += '<tr>';
for(j=0; j<3; j++)
{
tab.innerHTML += '<td id="'+i+''+j+'">'+i+''+j+'</td>';
}
tab.innerHTML += '</tr>';
}
The HTML being:
<table id="tab">
</table>
However, when I run the code all the table elements end up in the first column, so instead of a 3x3 table I get a 1x9 table.
Anyone know what I'm doing wrong?
tabonly once?