How to get table cell at specified index using jQuery

前端 未结 3 450
半阙折子戏
半阙折子戏 2020-12-14 16:17

I know that I can get first or last table cell (e.g. for last row) using jQuery expression like below:

first cell: $(\'#table tr:last td:first\') or las

相关标签:
3条回答
  • 2020-12-14 16:27

    Use the nth-child selector.

    For example,

    $('#table tr:last td:nth-child(2)')
    
    0 讨论(0)
  • 2020-12-14 16:37

    Yes:

    $('#table tr:last td:eq(1)')
    

    that will give you the second td in the last row.

    0 讨论(0)
  • 2020-12-14 16:41

    It's very simple without jQuery, and will work faster and in more browsers:

    var table = document.getElementById("table");
    var row = table.rows[table.rows.length - 1];
    var cell = row.cells[2];
    
    0 讨论(0)
提交回复
热议问题