You are here: Reference > JavaScript > client-side > event handling > events > onmouseenter

onmouseenter event | mouseenter event

Browser support:
Occurs when the user moves the mouse pointer into the area of an element.
The onmouseenter event is only supported by Internet Explorer, for a cross-browser solution, use the onmouseover event. The only difference between the onmouseenter and onmouseover events is that the onmouseover event propagates up the document hierarchy, while the onmouseenter does not.
Use the onmousemove event to receive a notification when the user moves the mouse pointer over, and the onmouseout event to receive a notification when the user moves the mouse pointer out of an element.
Note: the onmouseenter event is not fired during a drag operation. For that case, use the ondragenter event.

How to register:

In HTML:
<ELEMENT onmouseenter="handler">

In JavaScript:
object.onmouseenter = handler;
object.addEventListener ("mouseenter", handler, useCapture);
9
object.attachEvent ("onmouseenter", handler);
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers. The properties of the event object contain additional information about the current event. To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript.

Basic information:

Bubbles No
Cancelable No
Event object MouseEvent

Actions that invoke the onmouseenter event:

  • Moving the mouse pointer into an element.

The order of events related to the onmouseenter event:

Internet Explorer Firefox, Opera, Google Chrome, Safari
  1. onmouseover
  2. onmouseenter
  3. onmousemove
  4. onmouseout
  5. onmouseleave
  1. onmouseover
  2. onmousemove
  3. onmouseout

Example HTML code 1:

This example illustrates the use of the Internet Explorer specific onmouseenter and onmouseleave events:
<head>
    <script type="text/javascript">
        function OnMouseIn (elem) {
            elem.style.border = "2px solid blue";
        }
        function OnMouseOut (elem) {
            elem.style.border = "";
        }
    </script>
</head>
<body>
    <div style="background-color:#d0f0a0; width:200px" 
            onmouseenter="OnMouseIn (this)" onmouseleave="OnMouseOut (this)">
        Move your mouse pointer into and out of this element!
    </div>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

A cross-browser solution for the previous example:
<head>
    <script type="text/javascript">
        function OnMouseIn (elem) {
            elem.style.border = "2px solid blue";
        }
        function OnMouseOut (elem) {
            elem.style.border = "";
        }
    </script>
</head>
<body>
    <div style="background-color:#d0f0a0; width:200px" 
            onmouseover="OnMouseIn (this)" onmouseout="OnMouseOut (this)">
        Move your mouse pointer into and out of this element!
    </div>
</body>
Did you find this example helpful? yes no

Example HTML code 3:

This example dumps the order of events while the mouse moves into, over and out of an element:
<head>
    <script type="text/javascript">
        function DumpInfo (event) {
            var info = document.getElementById ("info");
            info.innerHTML += event.type + ", ";
        }
    </script>
</head>
<body>
    <div style="background-color:#d0f0a0; width:200px" 
            onmouseover="DumpInfo (event)" onmouseenter="DumpInfo (event)"
            onmousemove="DumpInfo (event)"
            onmouseout="DumpInfo (event)" onmouseleave="DumpInfo (event)">
        Move your mouse pointer into and out of this element!
    </div>
    <br /><br />
    <div id="info" style="background-color:#f0f0ff; font-weight:bold;"></div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content