We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

mouseleave Redirect 1

There was a scripting error on this page. While it is being addressed by site editors, you can view partial content below.

The mouseleave event is fired when a pointing device (usually a mouse) is moved off the element that has the listener attached.

Similar to mouseover, it differs in that it doesn't bubble and that it isn't sent until the pointer has moved from its physical space and the one of all its descendants.

mouseenter.png mouseover.png
One mouseenter event is sent to each element of the hierarchy when entering them. Here 4 events are sent to the four elements of the hierarchy when the pointer reaches the text. One single mouseover event is sent to the deepest element of the DOM tree, then it bubbles up the hierarchy until it is canceled by a handler or reaches the root.

With deep hierarchies, the amount of mouseleave events sent can be quite huge and cause significant performance problems. In such cases, it is better to listen for mouseout events.

Combined with the behavior of its symmetrical event, mouseenter, the mouseleave DOM Event acts in a very similar way to the CSS :hover pseudo-class.

  • Interface :MouseEvent
  • Synchronicity :synchronous
  • Bubbles : no
  • Target : element()
  • Cancelable : no
  • Default action : none

General info

Default Action


{{ MouseEventProperties }}
Property Type Description
target Read only EventTarget The event target (the topmost target in the DOM tree).
type Read only DOMString The type of event.
bubbles Read only boolean Does the event normally bubble?
cancelable Read only boolean Is it possible to cancel the event?
view Read only WindowProxy document.defaultView (window of the document)
detail Read only long (float) 0.


The mouseout documentation has an example illustrating the difference between mouseout and mouseleave.

The following example illustrates how to use mouseout to simulate the principle of event delegation for the mouseleave event.

<ul id="test">
    <ul class="leave-sensitive">
      <li>item 1-1</li>
      <li>item 1-2</li>
    <ul class="leave-sensitive">
      <li>item 2-1</li>
      <li>item 2-2</li>

  var delegationSelector = ".leave-sensitive";

  document.getElementById("test").addEventListener("mouseout", function( event ) {
    var target = event.target,
        related = event.relatedTarget,

    // search for a parent node matching the delegation selector
    while ( target && target != document && !( match = matches( target, delegationSelector ) ) ) {
        target = target.parentNode;

    // exit if no matching node has been found
    if ( !match ) { return; }

    // loop through the parent of the related target to make sure that it's not a child of the target
    while ( related && related != target && related != document ) {
        related = related.parentNode;

    // exit if this is the case
    if ( related == target ) { return; }

    // the "delegated mouseleave" handler can now be executed
    // change the color of the text
    target.style.color = "orange";
    // reset the color after a small amount of time
    setTimeout(function() {
        target.style.color = "";
    }, 500);
  }, false);
  // function used to check if a DOM element matches a given selector
  // the following code can be replaced by this IE8 compatible function: https://gist.github.com/2851541
  function matches( elem, selector ){
    // the matchesSelector is prefixed in most (if not all) browsers
    return elem.matchesSelector( selector );

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 30 crbug.com/236215 (Yes) bug 432698 5.5 17 ?
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ? ?

Document Tags and Contributors

Last updated by: ethertank,