Finding column index using jQuery when table contains column-spanning cells

后端 未结 5 1355
日久生厌
日久生厌 2020-12-01 12:08

Using jQuery, how can I find the column index of an arbitrary table cell in the example table below, such that cells spanning multiple columns have multiple indexes?

5条回答
  •  Happy的楠姐
    2020-12-01 13:06

    There is a more concise answer here: Get Index of a td considering the colspan using jquery

    In short:

    var index = 0;
    $("#example2").prevAll("td").each(function() {
        index += this.colSpan;
    });
    console.log(index);
    

提交回复
热议问题