How to give ID for TableRow using insertRow()?
var table = document.getElementById("table1");
var tr = table.insertRow();
var td = tr.i开发者_如何学CnsertCell();
td.innerHTML= document.getElementById('txt1').value;
i am using code like this. how to give Id for tr(TableRow). help me.
Just 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
精彩评论