.mouseout()
JQ Home <<
Events <<
.mouseout()
Mouseout event handler.
Description
The .mouseout()
method is used to bind an event handler to The JavaScript mouseout
event or trigger that event on the specified element.
- The
mouseout
event is sent to an element when the mouse pointer leaves the element it is bound to. - The
mouseout
event is similar to themouseleave
event but the events differ in the way they handle event bubbling:- The
mouseout
event triggers its handler when the mouse pointer leaves the element it is bound to, as well as any descendants. - The
mouseleave
event only triggers its handler when the mouse pointer leaves the element it is bound to, not any descendants.
- The
Syntax
Signature | Description |
---|---|
.mouseout( ) | Trigger the mouseout JavaScript event on the specified element. |
.mouseout( handler(eventObject) ) | Bind an event handler to the mouseout JavaScript event. |
.mouseout( [eventData ,] handler(eventObject) ) | Bind an event handler to the mouseout JavaScript event, optionally passing an object of data. |
Parameters
Parameter | Description | Type |
---|---|---|
handler( eventObject ) | A function to execute each time the event is triggered. | Function |
eventData | An object of data to pass to the event handler. | Anything |
Return
A jQuery
object.
.mouseout( )
Example
Events << Top
Trigger the mouseout
JavaScript event on the specified element.
- This signature is a shortcut for
.trigger('mouseout')
.
In the example below we show a new message in the 'div' element with an id of 'div1' every time the mouse leaves the division. Notice how the event also fires when the mouse leaves the image element, as
the mouseout
event triggers its handler when the mouse pointer leaves the element it is bound to, as well as any descendants.
When the mouse leaves the division or image, we trigger othe $('#div1').mouseout(function(){})
code which outputs the message.
$(function(){
$('#div12').mouseout(function () {
$('#div12').append('<br><code>mouseout</code> JavaScript event triggered.');
});
$('#div12').mouseout();
});
.mouseout( handler(eventObject) )
Example
Events << Top
Bind an event handler to the mouseout
JavaScript event.
- This signature is a shortcut for
.on('mouseout', handler)
.
In the example below we show a new message in the 'p' element with an id of 'scrollspan1' each time the 'div' element with an id of 'div2' below when the mouse leaves the division or image within it.
When the mouse leaves the division or image, the mouseout
JavaScript event fires off the addText(event)
mothod which outputs a message.
What we are doing here is passing across the event
object to the function addText(event)
method. The data we specify gets tagged onto the event.data
property.
$(function(){
$('#div2').mouseout(addText);
function addText(event) {
$('#scrollspan1').append('mouseout 1 **JavaScript event triggered**<br>');
}
});
We will show a message here.
.mouseout( [eventData ,] handler(eventObject) )
Example
Events << Top
Bind an event handler to the mouseout
JavaScript event, optionally passing an object of data.
- This signature is a shortcut for
.on('mouseout', handler)
.
In the example below we show a new message in the 'p' element with an id of 'scrollspan2' each time the 'div' element with an id of 'div3' below is left.
When the mouse button leaves the division or image, the mouseout
JavaScript event fires off the $('#div3').mouseout({ param1: '#scrollspan2', param2: 'mouseout 2 ', param3: '**JavaScript event triggered** ' }, addText2);
code.
What we are doing here is passing across the event
object to the function addText2(event)
. The map we specify, in our case { param1: '#scrollspan2', param2: 'mouseout 2 ', param3: '**JavaScript event triggered** ' }
gets tagged onto the event.data
property. We then access this parameter in the function via event.data.param
and use it as part of the appended data.
$(function(){
$('#div3').mouseout({ param1: '#scrollspan2', param2: 'mouseout 2 ',
param3: '**JavaScript event triggered****<br>' }, addText2);
function addText2(event) {
$(event.data.param1).append( event.data.param2 + event.data.param3);
}
});
We will show a message here.
Related Tutorials
jQuery Advanced Tutorials - Lesson 2 - Keyboard & Mouse Events