Reputation: 704
I have a div with this structure:
<div class="post" id="post-160439">
<a href="http://site blablabla" title="blablablabllba">
<img width="240" height="180" src="myimage.jpg"
class="attachment-240x180 wp-post- image" alt="my alt" title="my title"></a>
</div>
And I want to change the image on hover, I have (I think) the most part done, but can't get the point to change ONLY this image, not all images, Like this;
$('.wp-post-image').attr('src','my new image');
it changes all images, how can I tell jquery to change a divID.wp-post-image?
Thanks!!
Upvotes: 1
Views: 1744
Reputation: 44740
As you have multiple div's with images, you can try this:
$('div .post').each(function(){
$(this).find('img').hover(function(){
$(this).prop('src','my new image');
},
function(){
// callback
}
);
});
Upvotes: 0
Reputation: 104775
Try
$('#' + varHere + ' .wp-post-image').attr('src','my new image');
Upvotes: 1
Reputation: 1061
A faster option:
$( document.getElementById( "post-160439" ) ).find( 'wp-post-image' ).attr('src','my new image');
Upvotes: 0