jQuery mouseover()Method

jQuery 事件方法jQuery Event Methods

Examples

When the mouse pointer is over a <p> element, set the background color to yellow:

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

Try it yourself »

Definition and Usage

The mouseover event occurs when the mouse pointer is over an element.

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

Note:andmouseenterThe events are different: the mouseover event is triggered when the mouse pointer enters the selected element or any child element, while the mouseenter event is only triggered when the mouse pointer enters the selected element. See the demonstration example at the bottom of the page.

Tip:This event is usually used together with themouseoutevent together.


Syntax

Trigger the mouseover event of the selected element:

$(selector).mouseover() Try it yourself

Add a function to the mouseover event:

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

Parameters Description
function Optional. Specifies the function to run when the mouseover event is triggered.


实例

More Examples

The difference between mouseover() and mouseenter()
Demonstrates the difference between mouseover() and mouseenter().


jQuery 事件方法jQuery Event Methods

Other Extensions