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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:21:35+00:00 2026-06-15T16:21:35+00:00

Introduction: Hello everyone. I am trying to do a menu, but i have problem

  • 0

Introduction:
Hello everyone. I am trying to do a menu, but i have problem with mouseenter/mouseleave events.

What i have so far:

$("#icon").click(function() {
    $("#invis").css("display", "block");
    $("#icon").bind("mouseleave", function(){
        $("#invis").css('display', "none");
    }).bind("mouseenter", function(){
        $("#invis").css('display', "block"); 
    });
    $("#invis").bind("mouseleave", function(){
        $("#invis").css('display', "none");
    }).bind("mouseenter", function(){
        $("#invis").css('display', "block");
    });
});​  

So far, i tried this. My point is to click on the “icon”, and this click would show a menu/another, hidden element. Now i want to keep it open as long, as someone keeps mouse over “icon” or actual menu. But with code i provided, once i leave my mouse and then enter again on “icon”, it still keeps onmouseenter event, and menu will appear again. I know i could unbind onmouseenter event, but then once i drive off menu, onto icon, my menu would get closed, and i don’t want that.

Simplest example i could think of: http://jsfiddle.net/tzzqM/5/

Question
How to make “menu” open on click event, and then keep it open as long as someone keeps mouse over menu or “icon” (both of them). Once mouse leaves area of both, menu closes, and to open it i need to click once more on “icon”.
Is there a another way to do this?

  • 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-15T16:21:36+00:00Added an answer on June 15, 2026 at 4:21 pm

    On mouse leaving the object, check if the mouse is still either on the menu or on the menu-button, if not, hide the menu. Basically, you’re binding the event mouseleave to both elements and then checking the length of the selection. If it’s 1, you’re either on the menu or the button, this makes the exiting the menu button into the menu itself, not trigger the “hidding” part of the code, if the selection length is 0, then we are not over any of those elements and we hide it.

    $("#icon").click(function() {
        $("#invis").css("display", "block");
            $("#invis,#icon").bind("mouseleave", function(){
                if($("#invis:hover,#icon:hover").length === 0){
                    $("#invis").css('display', "none");
                }
            })
    });​
    

    There’s a fiddle here.

    Or the way I would write it if I had to start from scratch (just the jQuery part), since remember that you’d be jumping into the DOM pool less times and should be a little bit more efficient, although it’s as functional as the first one. Here’s the fiddle

    var icon = $("#icon"),
        menu = $("#invis");
    
    icon.click(function() {
        menu.show();
            $.merge(icon,menu).bind("mouseleave", function(){
                if($("#icon:hover,#invis:hover").length < 1) menu.hide();
            });
    });​
    

    Or using the suggestion from jhummel we can access the id of the new view that has the hover, and check if it’s one of the two that we want to monitor. This is great because it prevents us from jumping into the pool once more, this gives us a marginal performance boost, here’s the fiddle.

    var icon = $("#icon"),
        menu = $("#invis");
    
    icon.click(function() {
        menu.show();
            $.merge(icon,menu).bind("mouseleave", function(e){
                if($.inArray(e.relatedTarget.id, ["icon","invis"]) === -1){
                       menu.hide();
                }
            });
    });​
    

    ​


    Related docs:

    • jQuery.merge
    • Stop jumping into the pool!
    • jQuery.inArray
    • event.relatedTarget
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Introduction : Hello Everyone, I have been looking for days for a way to
INTRODUCTION : I have a function(callback) that receives a object as an argument, inside
Introduction Hello, I'm that typical programmer that know how to use api, but tend
Introduction Hello. I am a newbie to PHP programming. I have know the basics
Introduction of problem: I have two forms Home.cs and Login.cs . I have ToolStripMenuItems
Introduction: So, I have an interview tomorrow and I'm trying to review SQL and
Introduction I have a problem that I'm finding very mysterious. I've searched on Google
Hello I am trying to add ajax function to my site and it is
Introduction I have a question coming from this one: Loop calling an asynchronous function
Introduction I'm trying to query an xml column in SQL server 2008, but I

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.