leora
leora

Reputation: 196761

Using Jquery, what is the best way to read the 3rd column in a row from a html table

I have this code that read the first value in a html table

var firstNameinFirstCol = $(this).parents('tr:first').find('td:first').text();

this work great but now I need something that reads the 3rd column in that same row. Something like this

var lastNameinThirdCol = $(this).parents('tr:first').find('td:third').text();

does Jquery support something similar to this?

Upvotes: 1

Views: 182

Answers (1)

VisioN
VisioN

Reputation: 145458

How about using closest (instead of parents) and :eq()?

var lastNameinThirdCol = $(this).closest('tr').find('td:eq(2)').text();

Upvotes: 4

Related Questions