How to specify ID for TableRow using insertRow ()?

var table = document.getElementById("table1"); var tr = table.insertRow(); var td = tr.insertCell(); td.innerHTML= document.getElementById('txt1').value; 

I use this code. how to give Id for tr (TableRow). help me.

+6
source share
4 answers

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

+8
source

because you are using standard Javascript, you need to use the setAttribute ("align", "center", 0) function; '.

Try the following:

 tr.setAttribute("id", "myIdNameforThisRow", 0); 
+4
source
 var table = document.getElementById("table1"); var tr = table.insertRow(); tr.id = 'id_for_this_row'; // Just assign a value to the new row 'id' attribute var td = tr.insertCell(); td.innerHTML= document.getElementById('txt1').value; 
+2
source

create the variable first as var id = 0;

then

 tr.id=id; id++; 

use this code

0
source

Source: https://habr.com/ru/post/895671/


All Articles