Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Select first cell of a given row?

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.

like image 530
Dan Avatar asked Sep 15 '09 08:09

Dan


People also ask

How to get value of specific TD in jquery?

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


2 Answers

How about?

var a = $('td:first', $(this).parents('tr')).text();
like image 98
Daniel Elliott Avatar answered Sep 30 '22 16:09

Daniel Elliott


Here's another option:

var a = $(this).closest('tr').find('td:first').text();
like image 20
dcharles Avatar answered Sep 29 '22 16:09

dcharles