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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:47:47+00:00 2026-06-03T10:47:47+00:00

my website: http://modernego.info I have an <a> element named #btn-cart . When offered, it

  • 0

my website: http://modernego.info

I have an <a> element named #btn-cart. When offered, it drops down and shows a div named .block-cart. So this is how I want it to go:

If hovered on #btn-cart set .block-cart to display:block;
If hover out on #btn-cart set .block-cart todisplay:none;

If hovered on #btn-cart set .block-cart to display:block;
and then hovered onto .block-cart ignore the mouseleave on #btn-cart.

I got that working with the code below; however, when I set $('.block-cart').fadeOut(200), the .block-cart is set to display:none even if I hover on it.

Also, I am using .live because this cart is run through Ajax and without it the jQuery doesn’t work after the Ajax call. Is there a better way?

jQuery(function($) {
    $('#btn-cart').live('mouseenter', function() {
        $('.block-cart').css('display','block');                
    });
    //----------------------------------------------            
    $('.block-cart').live('mouseenter', function() {
        var close = false;
        $('.block-cart').css('display','block');    
    });
    //----------------------------------------------
    $('.block-cart').live('mouseleave', function() {
        close = false;
        $('.block-cart').fadeOut(200);   
    }); 
    //----------------------------------------------

    if (close != false) {   
        $('#btn-cart').live('mouseleave', function() {  
            $('.block-cart').fadeOut(200);
        });
    }

});

        <li class="hover hover-cart-sidebar">
                <a href="http://modernego.info/checkout/cart/" class="btn-cart hover-cart" id="btn-cart" title="Cart">

                        <span class="quantity">0</span>

                </a>    
                <div class="block block-cart">
    <div class="block-title">
    <strong><span>My Cart</span></strong>
</div>
<div class="block-content">
                        <p class="empty">Add something to your cart.</p>


        </div>
  • 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-03T10:47:50+00:00Added an answer on June 3, 2026 at 10:47 am

    I have done it so many times in so many different ways, but as I think about this question, I think the best way is to hack it with data attributes.

    Simplified example:

    HTML (simplified/dirty version, added input to check focus/hover on child elements)

    <div id="container">
        <a href="#" id="opener">open</a>
        <div id="menu">
            It's opened<br />
            <input /><br />
            Here
        </div>
    </div>
    

    JS *(should be optimized to avoid repeated DOM searches, but you get the
    * Updated to reflect fadeOut() instead of hide()
    * Updated to use on() instead of hover()

    $("#menu").hide();
    
    $("#container")
        .on("mouseenter", "#menu", function(){
            $(this).data("hover", true);
            $(this).show();
        })
        .on("mouseleave", "#menu", function(){
            $(this).data("hover", false);
            $(this).fadeOut(200);
        });
    
    $("#container")
        .on("mouseenter", "#opener", function(){
            $("#menu").show();
        })
        .on("mouseleave", "#opener", function(){
            setTimeout(function(){
                var menuHovered = $("#menu").data("hover");
                if(!menuHovered) {
                    $("#menu").fadeOut(200);
                }
            }, 50);
        });
    

    Fiddle

    http://jsfiddle.net/Meligy/GLG6A/ (using hover() width hide())
    http://jsfiddle.net/Meligy/GLG6A/3/ (using hover() width fadeOut(), only slight change)
    http://jsfiddle.net/Meligy/GLG6A/5/ (using on() on the elements instead of hover())
    http://jsfiddle.net/Meligy/GLG6A/6/ (using on() on the container, more realistic for AJAX)

    Credit:

    Got inspiration from here How do I check if the mouse is over an element in jQuery? and thought it work best and simplest, and it actually did! (in my tests at least)

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

Sidebar

Related Questions

I have website http://yournextleap.com/fresher-jobs Please find out last div having HTML <div data-recommendation= data-id=3790
i have an asp.net website http://www.site.com . This web app is also running on
I have (from the sed website http://sed.sourceforge.net/sed1line.txt ) this one-liner: sed -e '/./{H;$!d;}' -e
I have a website ( http://www.rtistree.com ) which has vertical scrollbar on some pages.
I have a big problem in website http://www.konasignature.com/ . While load my website in
So I have the following website: http://www.itmustbecollege.com/ and it has a problem SOMEWHERE that
I have two problems with my website : http://test2.tamarawobben.nl Problem 1 : In IE9
I saw that the website http://panopticlick.eff.org/ gather info about your browser, which makes you
I have the website : http://alfer-ks.eu5.org/dyer_galeri.html , and as you can see, some pictures
on this website: http://www.eco-environments.co.uk/ if you scroll down to What we do and rollover

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.