Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript, how can I access a specific child of a row?

Using Javascript, how can I access a specific child of a row? Javascript (not jQuery please).

e.g.: second <TD> of <TR> where ID=id33322010100167

<table>
<tr id="id33322010100167">
<td>20101001</td>
<td>918</td>
<td>919</td>
<td>67</td>
<td>CAR PROBLEM</td>
</tr>
<tr id="id33322010100169">
<td>20102001</td>
<td>913</td>
<td>914</td>
<td>62</td>
<td>LUNCHTIME</td>
</tr>
<table>
like image 431
robert Avatar asked Feb 03 '23 01:02

robert


2 Answers

var index = 1; // second element
var child = document.getElementById('id33322010100167').childNodes[index]
like image 121
RaYell Avatar answered Feb 05 '23 15:02

RaYell


Maybe you can try this:

var tRow = document.getElementById("tableName").getElementsByTagName("tr");

for(var i = 0; i < tRow.length; i++){
    if(tRow[i].id == "name of your id"){
        //do something
    }
}
like image 27
Shaoz Avatar answered Feb 05 '23 15:02

Shaoz