<!DOCTYPE html> <html> <head> <title>test</title> <script> var table=document.getElementById("myTable"); for (var i = 0, i < table.rows.length; i++) { var one=(table.rows.cells[1].innerHTML); document.write(one); } </script> </head> <body> <table border="1" id="myTable"> <tr> <td>a</td> <td>b</td> <td>c</td> </tr> <tr> <td>d</td> <td>e</td> <td>f</td> </tr> <tr> <td>g</td> <td>h</td> <td>i</td> </tr> </table> </body> </html> Code (markup): this is just a test to see whether tables can be iterated through using this method, however no output is produced using the javascript code. can anyone suggest why? please thanks
1) You should really NEVER use innerHTML. It's outdated, gets the parser involved, in cases like this could trigger reverse parsing. It's an outdated, outmoded, halfwit inept way of dealing markup. 2) Even if you WERE to use it, you're not indexing ROWS properly. You forgot to index by i var one = table.rows[i].cells[1].innerHTML; Code (markup): Really though, I would do this using the DOM since usually if it's a table you'd have a proper THEAD, and such routines you would only want to parse the TR inside TBODY.