Thursday, January 12, 2012

In jQuery what's the best way to add a class on mouseover and remove it on mouseout?


Is there a jQuery shortcut for this?




$(element).on("mouseover", function() {
$(this).addClass("hover");
}).on("mouseout", function() {
$(this).removeClass("hover");
});



I see in the jQuery docs a method called hover() , but that seems to bind on events mouseenter and mouseleave (should I be using those events instead of mouseover and mouseout ?)

No comments:

Post a Comment