Using getElementsByTagName('td') or querySelectorAll is the most sensible approach, but since you already know about tbodies , you might be interested to know about rows and cells .
A tbody element has the rows property, which is a set of tr elements, i.e. the lines it contains (unsurprisingly, right?). Each tr element as a property of cells , which is a set of td elements (here, too, is not surprising).
So technically you could do
for(var i = 0; i < table1.tBodies.length; i++) { var tbody = table1.tBodies[i]; for (var j = 0; j < tbody.rows.length; j++) { var row = tbody.rows[j]; for (var k = 0; k < row.cells.length; k++) { var cell = row.cells[k];
But such an enclosed loop cycle is difficult to read and maintain. Other answers show much better solutions.
You can find out about the tbody , tr and td properties in the MDN documentation.
source share