for(i = 0, i < rows, i++)
for(j = 0, j < columns, j++)
Now I just give it variables and it creates a dynamic table, right? Great.
But when I write something dynamically like that, and specify its "id" attribute, it's inaccessible. For instance, suppose the line:
Now I would expect each cell to have an id like, 00, 01, 02, 03... until I reach the last row/column pair.
var cell = document.getElementById("00");
always ends up returning null
Why is this? What am I doing wrong, and why is it working this way.
Here is another simple example where I get null values for elements by id:
var tbl =document.getElementById("myTable");
tbl.bgColor = document.getElementById("selBox").selectedIndex.text;
document.write("<table id=\"myTable\" border=\"1\"><tr><td>cell 1</td><td>cell 2</td></tr><tr><td>cell 3</td><td>cell 4</td></tr></table>");
document.write("<select id=\"selBox\" onclick=\"cell()\" value=\"Alert first cell\"><option>Blue</option></select>");
Please let me know what I'm doing wrong, and why it doesn't work like I expect. Thanks
- Anonymous4 years ago