I have a HTML table that contains both ROWSPANs and COLSPANs.
How can I find each cell\'s \"visual location\" using jQuery?
For example, here\'s a visual rep
for this specific layout (i.e. if your first row doesn't have colspan and more or less uniform cell borders) you may do it this way:
function getCellLocation(cell)
{
var row_number = cell.parentNode.rowIndex;
var col_number = "";
$(cell).parents('table').find('tr:first th').each( function()
{
if (cell.offsetLeft >= this.offsetLeft)
{
col_number = $(this).text();
}
else return false;
});
return col_number + row_number;
}
if you want numeric column change it to
var col_number = 0;
...
if (cell.offsetLeft >= this.offsetLeft)
{
col_number++;
}