[jQuery] Using parent within img toggle
I have a fairly simple app:
<table>
<thead>
<th>...
</thead>
<tbody>
<tr><td><img src="/images/deactivate.gif" class="active_toggle"></td></
tr>
<tr><td><img src="/image/deactivate.gif" class="active_toggle"></td></
tr>
<tr><td><img src="/image/deactivate.gif" class="active_toggle"></td></
tr>
</tbody>
</table>
then the following jquery toggles the src of the images back and forth
$("img.active_toggle").toggle(function(e){
// alert('change to reactivate');
$(this).attr("src","images/btnReactivate.gif")
}, function(e) {
// alert('change to deactivate');
$(this).attr("src","images/btnDeactivate.gif")
// hide a row after acknowledgement
});
What I would like to do now is add some jquery that changes the
background-color of the row containing the image that was clicked. My
thought was to use parent/parents, but nothing seems to be working:
$("img.active_toggle").toggle(function(e){
$(this).attr("src","images/btnReactivate.gif")
$(this).parent('tr').css("background-color","red")
return false;
}, function(e) {
$(this).attr("src","images/btnDeactivate.gif")
$(this).parent('tr').css("background-color","white")
});
Clicking the image toggles the src just fine, but the tr color never
changes.
thx!