Reputation: 3209
I have this div, inside the div I have a paragraph and inside the paragraph I have an image.
I am trying to display the closest image when I hover over my paragraph with this code:
$(function(){
$('.entry-content p').hover(function(){
//alert('heeeeey');
$('.entry-content p').css('width', '100%');
$('.entry-content p').closest('img').css('display', 'block');
});
});
But when I goto hover over my paragraph, the image does not display. Is there something wrong with my code?
Upvotes: 0
Views: 68
Reputation: 160833
.cloest()
is to find the the first match ancestor in the dom tree. A p
element won't have ancestor which is a image.
If the image is inside the p
element, try $('.entry-content p').find('img')
,
If the image is next to the p
element, try $('.entry-content p').next('img')
.
Upvotes: 1