jQuery Find Previous Table Row that has a Cell with a Specific Class
Posted
by Huy Tran
on Stack Overflow
See other posts from Stack Overflow
or by Huy Tran
Published on 2010-05-05T23:03:11Z
Indexed on
2010/05/05
23:08 UTC
Read the original article
Hit count: 125
jQuery
Hello All,
Suppose I have a table like so:
<table>
<tr><td class="this-is-a-label">Label Cell</td></tr>
<tr><td>Detail 1</td></tr>
<tr><td class="selected">Detail 2</td></tr>
</table>
I want to be able to grab the previous "Label Cell" from the "Selected" cell.
My jQuery script should be something like:
$('.selected').each(function() {
var label = $(this).parent().prev('tr td.this-is-a-label');
//... do what I need with the label ...
});
But it's not working.
Does anyone have any suggestions?
Thanks.
© Stack Overflow or respective owner