Wilson Wilson - 1 month ago 6
Javascript Question

Getting third cell of each row

var Rows = $("#tableid tbody tr");
Rows.each(function(index, element) {
var thirdCell = $(this+":nth-child(3)").text();
alert(thirdCell);
});


Something in the
var thirdCell
line is not working correctly. Each row has four children, all td tags. I want to get the text inside the third cell.

Answer

Try something like below,

var Rows = $("#tableid tbody tr");
Rows.each(function(index, element) {
var thirdCell = $(this).find('td').eq(2).text();
    alert(thirdCell);
});
Comments