A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

colIndex for td-, th- and col-Elements


I know, there exists celIndex, but it would be more usefull, if there was something like colIndex.

Additionaly, i would like a api like this on tr-Elements: tr.cellByColIndex(index);

Often we have to find cells in other rows that are in the same column. This works as long as there is no colspan, but if there is one, i have no quick access to the element like tr.children[index]

This api would also make sence on col-elements, since they represent a column.

Edit: changed category to “APIs”.


You mean tr > :nth-child(index), and no, it won’t work for the reasons the OP listed - if there’s any colspans (or rowspans from previous rows!), the child index doesn’t necessarily match the column index.


It’s a good idea. Along with this it would be worth considering table.cellByIndex(colIndex, rowIndex)

There does need to be consideration about what happens if indexing a spanned cell.

| 0 | 1 | 2 | 3 |
| 0 | 1     | 3 |
| 0 | 1 | 2 | 3 |

If I try and index cell (2, 1) would I get null because that cell doesn’t exist or would I get the cell (1,1) because it’s spanned into that indexed location? Should there also be properties on the element to tell if it’s spanned and which elements it spans over?


Yes, table.cellByIndex would be more important.

I just found the “nth-column-pseudo selector” in the css3 spec: https://www.w3.org/TR/selectors4/#the-nth-column-pseudo

So we can use this it lands in Browsers:

querySelectorAll('.myTable td:nth-column('+index+')')

But a js-api would be great too.