onmouseout event

Definition and usage

The onmouseout event occurs when the mouse pointer moves out of an element or one of its child elements.

Tip:This event is usually associated with onmouseover EventUsed together, this event occurs when the pointer moves over an element or one of its child elements.

Example

Example 1

Execute JavaScript when the mouse pointer moves out of the image:

<img onmouseout="normalImg(this)" src="smiley.gif" alt="Smiley">

Try it yourself

Example 2

This example demonstrates the difference between onmousemove, onmouseleave, and onmouseout events:

<div onmousemove="myMoveFunction()">
  <p id="demo">I will demonstrate onmousemove!</p>
</div>
<div onmouseleave="myLeaveFunction()">
  <p id="demo2">I will demonstrate onmouseleave!</p>
</div>
<div onmouseout="myOutFunction()">
  <p id="demo3">I will demonstrate onmouseout!</p>
</div>

Try it yourself

Syntax

In HTML:

<element onmouseout="myScript">

Try it yourself

In JavaScript:

object.onmouseout = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("mouseout", myScript);

Try it yourself

Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.

Technical details

Bubbling: Support
Cancelable: Support
Event types: MouseEvent
Supported HTML tags: All HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> and <title>
DOM Version: Level 2 Events

Browser Support

Events Chrome IE Firefox Safari Opera
onmouseout Support Support Support Support Support