views:

927

answers:

2

Hi, I have a table with images in one column. When I click the image, would like to get the text value of the first column in that row.

I can get the whole row with this:

var a = $(this).parents('tr').text();

However, I cannot isolate the first cell of the row.

I've tried

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

But that just returns the first cell of the entire table.

Can anyone help me out?

Thanks.

+1  A: 

How about?

var a = $('td:first', $(this).parents('tr')).text();

Kindness,

Dan

Daniel Elliott
var a = $('td:first', $(this).parents('tr')).text(); Thanks:)
Dan
Cool banana, editted to add :first
Daniel Elliott
In Prototype, you might go: var a = this.up('tr').down('td').innerHTML
arbales
A: 

Here's another option:

var a = $(this).closest('tr').find('td:first').text();
Marve