jQuery Find Previous Table Row that has a Cell with a Specific Class
- by Huy Tran
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.