var table = document.getElementById("table1");
var tr = table.insertRow();
var td = tr.insertCell();
td.innerHTML= document.getElementById('txt1').value;
i am using code like this. how to give Id for tr(TableRow). help me.
var table = document.getElementById("table1");
var tr = table.insertRow();
var td = tr.insertCell();
td.innerHTML= document.getElementById('txt1').value;
i am using code like this. how to give Id for tr(TableRow). help me.
Share Improve this question asked Aug 23, 2011 at 12:16 AravinthAravinth 1391 gold badge1 silver badge8 bronze badges4 Answers
Reset to default 18Just give tr.id = "some_id". This will work.
because you use standard Javascript you have to use the function setAttribute("align", "center", 0);
.
Try following:
tr.setAttribute("id", "myIdNameforThisRow", 0);
var table = document.getElementById("table1");
var tr = table.insertRow();
tr.id = 'id_for_this_row'; // Just assign a value to the new row's 'id' attribute
var td = tr.insertCell();
td.innerHTML= document.getElementById('txt1').value;
create a variable first like var id=0;
then
tr.id=id;
id++;
use this code