jQuery mouseenter() method
Example
When the mouse pointer enters the
element, set the background color to yellow:
$
(
"
p
"
)
.
mouseenter
(
function
(
)
{
$
(
"
p
"
)
.
css
(
"
background-color
"
,
"
yellow
"
)
;
}
)
;
Try it »
Definition and Usage
The mouseenter event occurs when the mouse pointer passes over (enters) the selected element.
The mouseenter() method triggers the mouseenter event, or adds a function to run when a mouseenter event occurs.
**Note:** Unlike the mouseover event, the mouseenter event is only triggered when the mouse pointer enters the selected element, while the mouseover event is also triggered when the mouse pointer enters any child element. See the demo at the bottom of the page.
**Tip:** This event is usually used together with the mouseleave event.
Syntax
Trigger the mouseenter event of the selected element:
$(
selector
).mouseenter()
Try it
Add a function to the mouseenter event:
$(
selector
).mouseenter(
function
)
Try it
| Parameters | Description |
|---|---|
| function | Optional. Specifies the function to run when the mouseenter event is triggered. |
More examples
The difference between mouseenter() and mouseover()
Demonstrate the difference between mouseenter() and mouseover().
jQuery event methods