Reputation: 3803
My sample HTML
<tr>
<td>
<div><span id="temp" />
</div>
</td>
</tr>
<tr>
<td>
<div><span id="temp" />
</div>
</td>
</tr>
From the Span tag how do i get the Table tr tag and set its background color ? Any easy methods rather than finding parent.parent?
And only the particular span tag TR should be changed not all the table TR ?
Thanks
Upvotes: 1
Views: 106
Reputation: 5895
Try .parents()
$('#temp').parents('tr').first().css({'background-color': '#fff'});
.first() exclude elements in cause of nested tables.
Or .closest()
$('#temp').closest('tr').css({'background-color': '#fff'});
Upvotes: 1
Reputation: 570
in jQuery:
$("#temp").parents("tr").css('background-color', 'green');
Upvotes: 1
Reputation: 44740
you can use .closest()
$('#temp').closest('tr').css('background-color', 'green');
Upvotes: 11