Dynamically Creating A Table In Javascript
I have got a working table that when the button is pushed, a table is dynamically created by looping through an array and displaying that data in each cell. However the problem ari
Solution 1:
You can use a loop to avoid duplicating code. For example:
var columns = ["Name", "Age", "Degree"];
var thd = document.createElement("thead");
tab.appendChild(thd);
var tr = document.createElement("tr");
thd.appendChild(tr);
for (var i = 0; i < columns.length; i++) {
var th = document.createElement("th");
th.appendChild(document.createTextNode(columns[i]));
tr.appendChild(th);
}
Post a Comment for "Dynamically Creating A Table In Javascript"