onmouseover event

Definition and usage

The onmouseover event occurs when the mouse pointer moves over the element or its child elements.

Tip:This event is usually associated with onmouseout EventUsed together, this event occurs when the user moves the mouse pointer out of the element.

Instance

Example 1

Execute JavaScript when the mouse pointer is moved over the image:

<img onmouseover="bigImg(this)" src="smiley.gif" alt="Smiley">

Try it yourself

Example 2

This example demonstrates the difference between onmousemove, onmouseenter, and mouseover events:

<div onmousemove="myMoveFunction()">
  <p id="demo">I will demonstrate onmousemove!</p>
</div>
<div onmouseenter="myEnterFunction()">
  <p id="demo2">I will demonstrate onmouseenter!</p>
</div>
<div onmouseover="myOverFunction()">
  <p id="demo3">I will demonstrate onmouseover!</p>
</div>

Try it yourself

Syntax

In HTML:

<element onmouseover="myScript">

Try it yourself

In JavaScript:

object.onmouseover = function(){myScript};

Try it yourself

In JavaScript, use the addEventListener() method:

object.addEventListener("mouseover", 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
onmouseover Support Support Support Support Support