javascript - How to target first td of every row with pure JS? -
i tried change color of first td element in each row red.
html:
<table id="test"> <tr> <td>test1</td> <td>test2</td> </tr> <tr> <td>test3</td> <td>test4</td> </tr> </table>
i tried js:
var tr = document.getelementsbytagname('tr'); tr.firstchild.style.color = 'red';
no jquery please.
use rows , cells access rows , columns of table. see below code,
var table = document.getelementbyid('test'); (var = 0; < table.rows.length; i++) { var firstcol = table.rows[i].cells[0]; //first column firstcol.style.color = 'red'; // or want first col }
Comments
Post a Comment