Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:40:23+00:00 2026-06-16T19:40:23+00:00

Possible Duplicate: Javascript: Multiple mouseout events triggered I keep having an issue where I’m

  • 0

Possible Duplicate:
Javascript: Multiple mouseout events triggered

I keep having an issue where I’m looking to see when my mouse exits a container, and the event is fired when I hover over an element contained within the container. I know that jQuery has fixed this problem with the .hover function, but I don’t want to use an entire library to solve a single problem. How do I do this in JavaScript?

My question is similar to this question, but I’m not using jQuery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:40:24+00:00Added an answer on June 16, 2026 at 7:40 pm

    Felix had the right answer with his first link. To quote from the article …

    Another show stopper is that when you move the mouse into the layer,
    and then onto a link, browsers register a mouseout event on the layer!
    It doesn’t make much sense to me (the mouse is still in the layer),
    but all browsers agree on this one.

    So how do we reject any mouseout that does not take place when the
    mouse actually leaves the layer?

    function doSomething(e) {
    if (!e) var e = window.event;
    var tg = (window.event) ? e.srcElement : e.target;
    if (tg.nodeName != 'DIV') return;
    var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
    while (reltg != tg && reltg.nodeName != 'BODY')
        reltg= reltg.parentNode
    if (reltg== tg) return;
    // Mouseout took place when mouse actually left layer
    // Handle event
    }
    

    First get the event target, ie. the element the mouse moved out of. If
    the target is not the DIV (layer), end the function immediately, since
    the mouse has certainly not left the layer.

    If the target is the layer, we’re still not sure if the mouse left the
    layer or entered a link within the layer. Therefore we’re going to
    check the relatedTarget/toElement of the event, ie. the element the
    mouse moved to.

    We read out this element, and then we’re going to move upwards through
    the DOM tree until we either encounter the target of the event (ie.
    the DIV), or the body element.

    If we encounter the target the mouse moves towards a child element of
    the layer, so the mouse has not actually left the layer. We stop the
    function.

    When the function has survived all these checks we’re certain that the
    mouse has actually left the layer and we can take appropriate action
    (usually making the layer invisible).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Javascript infamous Loop problem? I am having a small issue, and it
Possible Duplicate: Javascript: The prettiest way to compare one value against multiple values Javascript
Possible Duplicate: JavaScript move delay and multiple keystrokes I'm new and learning HTML5 canvas
Possible Duplicate: How can I match multiple occurrences with a regex in JavaScript similar
Possible Duplicate: How can I match multiple occurrences with a regex in JavaScript similar
Possible Duplicate: JavaScript: How do I print multiple script tags in a loop? Im
Possible Duplicate: Declaring Multiple Variables in JavaScript I was setting some variables in jQuery
Possible Duplicate: javascript resize event firing multiple times while dragging the resize handle Tried
Possible Duplicate: Javascript multiple replace How do I replace all occurrences of "/" in
Possible Duplicate: JQuery - multiple $(document).ready … ? What are the implications of having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.