Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give ID for TableRow using insertRow()?

Tags:

javascript

 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.

like image 232
Aravinth Avatar asked Aug 23 '11 12:08

Aravinth


People also ask

How do you insert 3 rows before the last row of a table?

Click in a cell above or below where you want to add a row. Under Table Tools, on the Layout tab, do one of the following: To add a row above the cell, click Insert Above in the Rows and Columns group. To add a row below the cell, click Insert Below in the Rows and Columns group.

How to add a new row to a table in HTML?

The insertRow() method creates an empty <tr> element and adds it to a table. The insertRow() method inserts the new row(s) at the specified index in the table. Note: A <tr> element must contain one or more <th> or <td> elements. Tip: Use the deleteRow() method to remove a row.


3 Answers

Just give tr.id = "some_id". This will work.

like image 70
AmGates Avatar answered Sep 20 '22 15:09

AmGates


because you use standard Javascript you have to use the function setAttribute("align", "center", 0);.

Try following:

tr.setAttribute("id", "myIdNameforThisRow", 0);
like image 40
Reporter Avatar answered Sep 17 '22 15:09

Reporter


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; 
like image 40
DaveRandom Avatar answered Sep 18 '22 15:09

DaveRandom