jQuery mouseenter()Method

jQuery 事件方法jQuery Event Methods

Example

When the mouse pointer enters the <p> element, set the background color to yellow:

$("p").mouseenter(function(){ $("p").css("background-color","yellow"); });

Try it yourself »

Definition and Usage

When the mouse pointer passes through (enters) the selected element, the mouseenter event occurs.

The mouseenter() method triggers the mouseenter event, or adds a function to run when the mouseenter event occurs.

Note:andmouseoverThe events are different: 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 demonstration example at the bottom of the page.

Tip:This event is usually used withmouseleaveevent.


Syntax

Trigger the mouseenter event of the selected element:

$(selector).mouseenter() Try it yourself

Add a function to the mouseenter event:

$(selector).mouseenter(function) Try it yourself

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 事件方法jQuery Event Methods

Other Extensions