rwur rwur - 7 months ago 33
jQuery Question

Table column index with previous rowspan columns

I have the following jsfiddle ready to show you my problem


Live Demo

Basically the problem I have is a table column where I have rowspan assigned to.

I want to get the right column index.

I hope my fiddle is good enough to explain my problem :-)

Hope anyone can help?


Well, I know that you've already got an answer by try this variant. It's based on calculating indexes and should work for any cell. And I've removed duplicate id attributes in jsFiddle.

    var clickedEl = $(this);
    var myCol = clickedEl.closest("td").index();
    var myRow = clickedEl.closest("tr").index();
    var rowspans = $("td[rowspan]");
    rowspans.each(function () {
        var rs = $(this);
        var rsIndex = rs.closest("tr").index();
        var rsQuantity = parseInt(rs.attr("rowspan"));
        if (myRow > rsIndex && myRow <= rsIndex + rsQuantity - 1) {
    alert('Row: ' + myRow + ', Column: ' + myCol);

Here is a demo in jsFiddle. Just want to solve your problem with this approach =).