I am going thru a strange problem,I added hover function to my list items which are generated dynamically using ajax, but nothing is happening.The code is executing without any errors but with no effect.Even the alert is not displaying for mouseenter and mouseout.The alert pops up once in a while but not everytime.I am using the following code.
$('.category_list li').live("mouseenter", function() {
alert('I m here');
$(this).find('.category_list').css('text-decoration','underline');
}).live("mouseleave", function() {
alert('I m gone');
$(this).find('.category_list').css('text-decoration','none');
});
My html code is
htmlData.push('<ul class="category_list">');
htmlData.push('<li><a href="javascript:void(0);" onclick="callGetApplicationDetails('+iIndex+',0);" >'+categoryName+'</a></li>');
Please help me since i am stuck very badly.
thanks Hemish
Try using the
mouseover
andmouseout
events. I believe your filtering selector was looking for the<li>
elements parent?and you could probably clean up the jQuery a little with a new css class
and use
toggleClass()
Finally! I used livequery and it worked!
@Patrick:Thanks for the help.
Hope it will help others also.
If you don't need to support IE6 with this feature, use CSS instead:
Example: http://jsfiddle.net/QLsQp/
This uses the
:hover
pseudo selector to affect the nesteda
element when ali
is hovered.The trouble with your javascript is that this:
...won't find anything, because
.category_list
is an ancestor of the<li>
elements, not a descendant.You would need this instead: