jQuery hover

03.Sep.2010

Not often used – jQuery hover is a function that lets you write only one function instead of two for handling mouseenter and mouseleave events. It is a useful function when you want to create drop down menus. In order to use it, you have to send two parameters to jQuery hover function. Two functions that define behavior on events mouseenter and mouseleave respectively.

This snippet is an example of jQuery hover function:

1
2
3
4
5
6
7
8
9
10
jQuery("#element").hover(
	function () {
		//this handles mouseenter event
		jQuery(this).addClass("active");
	},
	function () {
		//this handles mouseleave event
		jQuery(this).removeClass("active");
	}
);