Hi all, I want to read a table from a web page and populate something else with those data. I can access the whole table by it's Id, which is known. So, I do something like : Code: var myTable = document.getElementById("Table_A"); Now, how can I read the data in the different rows and columns and use them ? Thanx in advance
OK. I finally got it To help other members who might face the same problem in future, I am posting my solution here : The only thing that saves us in this situation is "getElementsByTagName". So, you can do it like this : Code: // get the table. var myTable = document.getElementById("Table_A"); // get all rows inside the table var allRows = myTable.getElementsByTagName("TR"); // variables to store all cells in a row var allCells; for(var x=0; x < allRows.length; ++x) { // get all the cells in row x allCells = allRows[x].getElementsByTagName("TD"); // do whatever you like ... :) }
getElementsByTagName is definitely an option but there are others like getElementById and getElementByClass