I'm having trouble creating a table with 2 rows, each row containing 4 cells that should display an image. However, when I try to execute my function, nothing seems to happen. Can you help me troubleshoot?
function generateTable()
{
var table = document.createElement("TABLE");
table.setAttribute("id", "gameBoard");
var row1 = document.createElement("TR");
row1.setAttribute("id", "r1");
table.appendChild(row1);
for (var i = 0; i < 4; i++)
{
var cell = document.createElement("TD");
var cell_img = document.createElement('img');
cell_img.setAttribute("src", "images/card_back.png");
cell.appendChild(cell_img);
row1.appendChild(cell);
}
var row2 = document.createElement("TR");
row2.setAttribute("id", "r2");
table.appendChild(row2);
for (var j = 0; j < 4; j++)
{
var cell = document.createElement("TD");
var cell_img = document.createElement('img');
cell_img.setAttribute("src", "images/card_back.png");
cell.appendChild(cell_img);
row2.appendChild(cell);
}
}
}