Javascript, how can I access a specific edge of a string?

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

for example: 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> 
+6
javascript html-table row
source share
5 answers
 var index = 1; // second element var child = document.getElementById('id33322010100167').childNodes[index] 
+5
source share

Perhaps you can try the following:

 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 } } 
+3
source share

The most reliable collection of cells , which unlike childNodes in browsers other than IE, ignores whitespace text nodes between cells:

 var td = document.getElementById("id33322010100167").cells[1]; 
+1
source share

Using the DOM, you can get the table and then iterate over the children, keeping the score.

Of course, item identifiers must be unique, so document.getElementById('id') works.

0
source share

Use jQuery :

 first = $('#id33322010100167 td:first'); // gives you the first td of the tr with id id33322010100167 last = $('#id33322010100167 td:last'); // gives you the last td of the tr with id id33322010100167 

you can use next () to repeat elements

 first.next(); 
0
source share

All Articles