A repository of over 1000 quality jQuery plugins

jQuery .mouseover()

Learn all about the jQuery function .mouseover().

This method is a shortcut for .on( "mouseover", handler ) in the first two variations, and .trigger( "mouseover" ) in the third.

The mouseover event is sent to an element when the mouse pointer enters the element. Any HTML element can receive this event.

For example, consider the HTML:

1
2
3
4
5
6
7
8
9
10
<div id="outer">
Outer
<div id="inner">
Inner
</div>
</div>
<div id="other">
Trigger the handler
</div>
<div id="log"></div>

figure 1

The event handler can be bound to any element:

1
2
3
$( "#outer" ).mouseover(function() {
$( "#log" ).append( "<div>Handler for .mouseover() called.</div>" );
});

Now when the mouse pointer moves over the Outer <div>, the message is appended to <div id="log">. We can also trigger the event when another element is clicked:

1
2
3
$( "#other" ).click(function() {
$( "#outer" ).mouseover();
});

After this code executes, clicks on Trigger the handler will also append the message.

This event type can cause many headaches due to event bubbling. For instance, when the mouse pointer moves over the Inner element in this example, a mouseover event will be sent to that, then trickle up to Outer. This can trigger our bound mouseover handler at inopportune times. See the discussion for .mouseenter() for a useful alternative.