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 6919649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:01:04+00:00 2026-05-27T10:01:04+00:00

I have the following code. (You can copy it into a file to debug

  • 0

I have the following code. (You can copy it into a file to debug in Firefox, and see the outputs in the Console Tab in Firebug).

When I add onmouseover envent to the li tags, and move the mouse into the li area, the console info comes out.

The problem is when I moving the mouse from the image (Google logo) to the text under it, multiple info are print out. Why does the onmouseout event triggered, since I don’t leave the li area?

What should I do to prevent triggering the onmouseout events in this situation.

Thank you!!

<html>
<body>

<div>
    <ul>
        <li onmouseover="console.info('over')" onmouseout="console.info('out')" style="float:left;display:block;width:30%;height:200px;border: 2px solid red;">
            <img src="https://www.google.com/intl/en_com/images/srpr/logo3w.png">
            <br/>
            <br/>
            <a href="#">Google</a>
        </li>
        <li style="float:left;display:block;width:30%;">
            <img src="https://www.google.com/intl/en_com/images/srpr/logo3w.png">
            <br/>
            <br/>
            <a href="#">Google</a>
        </li>
        <li style="float:left;display:block;width:30%;">
            <img src="https://www.google.com/intl/en_com/images/srpr/logo3w.png">
            <br/>
            <br/>
            <a href="#">Google</a>
        </li>
    </ul>
</div>

</body>
</html>
  • 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-05-27T10:01:05+00:00Added an answer on May 27, 2026 at 10:01 am

    Events bubble up the DOM tree. So when the cursor leaves the img element, a mouseout event is generated and triggers the event handler bound to the parent li element.

    There are two ways you can deal with this situation:

    Prevent the event from bubbling

    If you want to prevent the event from bubbling up, you assign an event handler to the element the event originates and call the event object’s stopPropagation method (or cancelBubble property in IE):

    function handler(event) {
        event = event || window.event; // IE
        if(event.stopPropagation) {
            event.stopPropagation();   // W3C
        }
        else {
            event.cancelBubble = true; // IE
        }
    }
    

    The problem is that you have to bind this handler to every child element, which is not very convenient. Therefore, the following way is easier to realise.

    Test where the event originates

    You can get a reference to the element where the event originates with event.target (or event.srcElement in IE). The event handler you bind to the li element should look like this then:

    function handler(event) {
        event = event || window.event; // IE
        var target = event.target || event.srcElement; // IE
    
        if(target === this) {   // event originated where the handler was bound to
            console.info('out');
        }
    }
    

    and call it with

    onmouseout="handler.call(this, event);"
    

    Note that binding the event handlers inline, like you do, is bad design, as it mixes presentation with application logic. There are two other ways to bind event handlers


    I recommend to read the articles about event handling on quirksmode.org.

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

Sidebar

Related Questions

i have written the following code: As you can see there is a for
Please can someone help? I have the following code which uploads a file to
I have the following code and I can't understand what does it mean: var1
I have the following code to do this, but how can I do it
I have a simple 3D cube that I can rotate using the following code:
According to what I have found so far, I can use the following code:
Following on from this question I now have code that can attach to a
We have similar code to the following in one of our projects. Can anyone
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section

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.