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 } 

demo: http://jsfiddle.net/qneyx/


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -