Finding a colSpan Header for one of the cells or td's is Spans

后端 未结 2 1265
暖寄归人
暖寄归人 2020-12-22 08:13

I have multiple column headers that spans of multiple column and I would like to find the correct header number/count for the columns.

I want to enter a column numbe

2条回答
  •  攒了一身酷
    2020-12-22 08:27

    That's easy, as long as you don't have any rowspans:

    function getCell(tr, col) {
        var cell = tr.firstElementChild;
        while (cell && (col -= cell.colSpan || 1)>=0)
            cell = cell.nextElementSibling;
        return cell;
    }
    

    See demonstration.

提交回复
热议问题