I've run into a Javascript/JQuery issue I was hoping you'd know how to solve.
Suppose I define this function that builds a table inside of the 'div' with id 'TableHolder':
MakeTable = function()
{
document.getElementById('TableHolder').innerHTML = "";
var tablebuild = "<table><tbody><tr>";
for (i=0; i<3; i++)
{
tablebuild += "<td></td>";
}
tablebuild += "</tr></tbody></table>";
document.getElementById('TableHolder').innerHTML = tablebuild;
}
I call this function when the document is ready, and tell JQuery to rebuild the table when any cells are clicked.
$(document).ready(function() {
MakeTable();
$('td').click(function(){
MakeTable();
}
});
Once a cell is clicked and MakeTable() rebuilds the table, the JQuery no longer works for the new cells.
Is there any way to fix this issue without using a loop?
*The above is a bread and butter version of a program that actually has a purpose, and I recognize it's useless as presented. Yet, the solution applies across the board.