In POJS (plain old javascript):
HTML:
<table id="foo"> <thead></thead> <tbody> <tr> <td>1</td> <td colspan="2">2</td> <td colspan="3">3</td> </tr> </tbody> <tfoot></tfoot> </table>
JS:
var foo = document.getElementById("foo"), i = 0, j = 0, row, cell, numCols = 0; //loop through HTMLTableElement.rows (includes thead, tbody, tfoot) for(i;i<foo.rows.length;i++) { row = foo.rows[i]; //loop through HTMLTableRowElement.cells for(j = 0;j<row.cells.length;j++) { cell = row.cells[j]; numCols += cell.colSpan; cell = null; } row = null; } alert(numCols) //6;
HTMLTableElement .rows will collect lines from each HTMLTableSectionElement (THead, TBody and TFoot). Each section also has its own rows HTMLCollection, so you can filter them if necessary.
user1385191 Jul 13 '11 at 19:02 2011-07-13 19:02
source share