Reputation: 2110
I have a few <li>
tags and I need to hide an element inside of the hovered <li>
tag.
The following code is not working, please let me know how can I get it worked...
$(function(){
$("#deals ul li").hover(function(){
$(this:has(".transform")).hide();
});
});
Thanks.
Upvotes: 1
Views: 68
Reputation: 237975
this
is a DOM element. You can't combine it with jQuery selectors or strings to try to find an element. $(this)
is a jQuery selection containing the element hovered. You probably need to use find
to get the element you want:
$(function(){
$("#deals ul li").hover(function(){
$(this).find(".transform")).hide();
});
});
I think you may also want the mouseenter
event, rather than hover
, if you are only binding a handler for the time when the mouse hovers over the element, rather than when it leaves it too.
Upvotes: 3
Reputation: 382806
Replace:
$(this:has(".transform")).hide();
With:
$(this).find(".transform")).hide();
Upvotes: 1