Contents:
.hover( handlerIn, handlerOut )Returns: jQueryversion deprecated: 3.3
Description: Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.
-
version added: 1.0.hover( handlerIn, handlerOut )
-
handlerInA function to execute when the mouse pointer enters the element.
-
handlerOutA function to execute when the mouse pointer leaves the element.
-
.on( "mouseenter", handlerIn ).on( "mouseleave", handlerOut )
instead.
.hover()
method binds handlers for both mouseenter
and mouseleave
events. You can use it to simply apply behavior to an element during the time the mouse is within the element.
$( selector ).hover( handlerIn, handlerOut )
is shorthand for:
1
|
|
mouseenter
and mouseleave
for more details.
Examples:
Example 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
|
Demo:
Example 2
1
2
3
4
5
6
7
|
|
Example 3
1
|
|
.hover( handlerInOut )Returns: jQueryversion deprecated: 3.3
Description: Bind a single handler to the matched elements, to be executed when the mouse pointer enters or leaves the elements.
-
version added: 1.4.hover( handlerInOut )
-
handlerInOutA function to execute when the mouse pointer enters or leaves the element.
-
.on( "mouseenter mouseleave", handlerInOut )
instead.
.hover()
method, when passed a single function, will execute that handler for both mouseenter
and mouseleave
events. This allows the user to use jQuery's various toggle methods within the handler or to respond differently within the handler depending on the event.type
.
$(selector).hover(handlerInOut)
is shorthand for:
1
|
|
mouseenter
and mouseleave
for more details.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
|