I want when mouse goes on li
jquery add a class to the element:
This will work, when you mouse over li it will add is_hovered
to li and remove from other li.
$(".menu li").mouseover(function(){
$(".menu li").removeClass("is_hovered");
$(this).addClass("is_hovered");
});
Don't use the mouseleave handler in that case, on mouseenter remove the hovered class from other elements
var myMenu = $('.menu li');
myMenu.mouseenter(function () {
myMenu.filter('.is_hovered').removeClass("is_hovered");
$(this).addClass("is_hovered");
});
Demo: Fiddle