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 last cell: $('#table tr:last td:last')
But, how can I get cell at specific index, for example index 2, using similar expression, i.e. something like $('#table tr:last td:[2]')
?
Regards.
jQuery: code to get TD text value on button click. text() method we get the TD value (table cell value). So our code to get table td text value looks like as written below. $(document). ready(function(){ // code to read selected table row cell data (values).
$(function() { var bid, trid; $('#test tr'). click(function() { trid = $(this). attr('id'); // table row ID alert(trid); }); });
$(this). closest('tr'). children('td:eq(0)'). text();
Yes:
$('#table tr:last td:eq(1)')
that will give you the second td
in the last row.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With