Thursday, March 12, 2009

Adding a Row Dynamically to a HTML Table using JavaScript

The following code part can be used to add a new row and a cell to a html table dynamically using javascript.
var tbl = document.getElementById('table_id');
var lastRow = tbl.rows.length;
// this adds the row to the end of the table
var row = tbl.insertRow(lastRow);
var cell1 = row.insertCell(0);
var textNode = document.createTextNode("Hello World");
by creating set of cells you can append to the row which you have created.

No comments: