Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  98] [ 3]  / answers: 1 / hits: 65477  / 13 Years ago, mon, april 11, 2011, 12:00:00

I want to manipulate table cells with javascript, and so far I managed to get into tr-s, by using:



var as = document.getElementById('answers['+id+']');
var trs = as.getElementsByTagName(tr);
for (var i in trs)
{ ... }


UPDATE: The as variable contains a reference to the table.



Inside of the for cycle I wanted to go on the same login line and I have tried:



var tds = trs[i].getElementByTagName(td);


The problem is that on debugging I get the following error:



Uncaught TypeError: Object #<HTMLTableRowElement> has no method 'getElementByTagName' .


How could I get into the td-s of the tr-s?


More From » html

 Answers
32

its getElementsByTagName and not getElementByTagName



var as = document.getElementById('answers['+id+']');
for(var i=0;i<as.rows.length;i++) {
var trs = as.getElementsByTagName(tr)[i];
var cellVal=trs.cells[0]
}


the variable cellVal will give the reference to the first cell or <td> similarly do for all the cells by increasing the index or putting it in a loop would make it dynamic...


[#92813] Saturday, April 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaceyr

Total Points: 510
Total Questions: 97
Total Answers: 116

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
kaceyr questions
;