Reputation: 1423
Assuming I have a set up of:
<ul id="cal">
<li><span>test</span><img /></li>
<li><span>test</span><img /></li>
<li><span>test</span><img /></li>
</ul>
and in the jQuery:
$('#cal li span').hover(function(){
$("#cal li img").trigger('mouseover');
});
I need to trigger mouseover on the #cal li img, but on only the image of the span rather than all of the images
Upvotes: 0
Views: 80
Reputation: 26940
$('#cal li span').hover(function(){
$(this).next("img").trigger('mouseover');
});
Upvotes: 0
Reputation: 8275
Specify it is linked to your context with:
$('#cal li span').hover(function(){
$(this).parent().find("img").trigger('mouseover');
});
Upvotes: 1
Reputation: 145458
You can refer to closest <img>
using $(this).next()
or with:
$("#cal li span").hover(function() {
$(this).siblings("img").trigger("mouseover");
});
Upvotes: 3