Search code examples
javascriptjqueryhtmlindexinghtml-table

Getting td by index with jQuery


I know how to get a cell's row and column index with jQuery, but I can't figure out the reverse. Given a row and column index, how would I access the td at this location?


Solution

  • With plain JavaScript:

    // table is a reference to your table
    table.rows[rowIndex].cells[columnIndex]
    

    Reference: HTMLTableElement, HTMLTableRowElement


    With jQuery, you could use .eq():

    $('#table tr').eq(rowIndex).find('td').eq(columnIndex)
    // or
    $('#table tr:eq(' + rowIndex + ') td:eq(' + columnIndex + ')')