Reputation: 23979
I have the following html structure:
<div class="hold_image">
<div class="SiteName">guitars.com</div>
<a href="/image/Guitars/1236">
<img src="//mysite.com/images/production/1236.jpg" class="Image">
</a>
</div>
I want to change the parent outer div (class="hold_image") to have a different color background when the image loads and am trying:
$(".Image").on('load', function () {
$(this).prev('.hold_image').css('background-color','#ffffff');
});
But nothing changes. Is there a better way to do this?
Upvotes: 0
Views: 37
Reputation: 6455
Hi instead of prev
you want to use closest('.hold_image')
. This selector searches up the dom tree until it has a match.
Upvotes: 1