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.
-
This API is deprecated. Use .on( "mouseenter", handlerIn ).on( "mouseleave", handlerOut )
instead.
The .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.
Calling $( selector ).hover( handlerIn, handlerOut )
is shorthand for:
1
|
|
See the discussions for mouseenter
and mouseleave
for more details.
Examples:
To add a special style to list items that are being hovered over, try:
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:
To add a special style to table cells that are being hovered over, try:
1
2
3
4
5
6
7
|
|
To unbind the above example use:
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.
-
This API is deprecated. Use .on( "mouseenter mouseleave", handlerInOut )
instead.
The .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
.
Calling $(selector).hover(handlerInOut)
is shorthand for:
1
|
|
See the discussions for mouseenter
and mouseleave
for more details.
Example:
Slide the next sibling LI up or down on hover, and toggle a class.
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
|
|