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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:14:36+00:00 2026-05-20T00:14:36+00:00

I have two div classes, say A and B. When the mouse is over

  • 0

I have two div classes, say A and B. When the mouse is over div A, div B should appear, then if the mouse is over A or B, div B should stay opened. If the mouse is out of both, A and B divs, B should disappear. (As you probably guess this is a simple tooltip script)

enter image description here

This is the jquery code I wrote:

$(document).ready(function() {
    function show() {
        $("BBB").css({'display':'block'});
    }

    $("AAA").each(function() {
        $(this).mouseover(function() {
            show();
        });

        $(this).mouseleave(function() {
            time = setTimeout("hide()", 200);
        });

        $("BBB").mouseleave(function() {
            setTimeout("hide()", 200);
        });

        $("BBB").mouseenter(function() {
            clearTimeout(time);
        });
    });
});

function hide() {
    $("BBB").css({'display':'none'});
}

The problem is that when I move from B to A, B disappears! I want to it to disappear only if the mouse is neither over A, nor B. How can I fix this problem?

  • 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-20T00:14:37+00:00Added an answer on May 20, 2026 at 12:14 am

    There are a few small problems with your code. The one which is biting your right now is that you aren’t clearing BBB’s timeout when you enter AAA. You can fix this by adding a clearTimeout to AAA’s mouseover handler.

    Secondly, it’s safest to clear this kind of timeout before you set it each time, so that you don’t have your timeout tracking overwritten if something unexpected happens. (It’s always safe to clear a timeout, even if it’s invalid or has already occurred.)

    Lastly, though this is most likely only a problem in your example code, you’re leaking time into the global object. 😉

    Try this instead:

    $(document).ready(function() {
        var time;
    
        function show() {
            $("BBB").css({'display':'block'});
        }
    
        $("AAA").each(function() {
            $(this).mouseover(function() {
                clearTimeout(time);
                show();
            });
    
            $(this).mouseleave(function() {
                clearTimeout(time);
                time = setTimeout("hide()", 200);
            });
    
            $("BBB").mouseleave(function() {
                clearTimeout(time);
                time = setTimeout("hide()", 200);
            });
    
            $("BBB").mouseenter(function() {
                clearTimeout(time);
            });
        });
    });
    
    function hide() {
        $("BBB").css({'display':'none'});
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a container div that holds two internal divs; both should take 100%
Say I have a div that uses two css classes that both use text-align,
I have two divs inside a div, I want them both adjacent to each
I have two divs both containing images. Here is some example code: <div id=one>
I have a div with two nested divs inside, the (float:left) one is the
I have two div's which classes are left and right. left is floated to
Okay I have two classes for two links and two divs with different information.
I have an ASP.NET page that contains two div's. Both have search fields and
If you have two divs contained within a div: <div style=border:1px;> <div style=float:left;background-color:red;width:20px;height:20px;> <div
I have two divs #left , and #right . the right div has a

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.