Click to See Complete Forum and Search --> : Table - insertRow()


saju_m
01-28-2003, 04:29 AM
Hi,
How to add a new row on a table by clicking a button,

Please help

Thank You,

khalidali63
01-28-2003, 07:34 AM
Well here is how you can add a table row in NS6+/Mozilla 1+ browsers.
it is one of the ways.

get the id of the table
var tbl = document.getElementById("tableID");

now create new TR element

var tr = document.createElement("tr");
set attribute values for this tr
tr.setAttribute("style","font-size:8pt;");

Now say you wanted to add a TD element as well.

var td = document.createElement("td");
td.setAttribute("style","width:200pt;");
and say there is some text you want to display in this td element.

td.appendChild(document.createTextNode("its the DOM td");

now follow the hiereachy and add elements upto the table.
tble.appendChild(tr.appendChild(td));

And there you go you have just added table elelments using DOM.

BTW in IE once you have created rows then you can add TD elements and text values
like this
row.inserCell()
cell.innerText="this is IE td";

cheers

Khalid