Reputation: 139
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.
Upvotes: 9
Views: 46592
Reputation: 3948
because you use standard Javascript you have to use the function setAttribute("align", "center", 0);
.
Try following:
tr.setAttribute("id", "myIdNameforThisRow", 0);
Upvotes: 7
Reputation: 395
create a variable first like var id=0;
then
tr.id=id;
id++;
use this code
Upvotes: 0
Reputation: 88697
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;
Upvotes: 2