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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:56:31+00:00 2026-05-24T10:56:31+00:00

The title is a little bit messy, so let me try to explain in

  • 0

The title is a little bit messy, so let me try to explain in the actual question:

Suppose I have the following HTML setup.

<div id="userMenu">
    <div id="userMenu-expanderLink">Mouseover here!</div>
    <div id="userMenu-collapserLink">You can close the menu by mouse out.</div>
    <div id="userMenu-expandedContent">Extra Content</div>
</div>

Now, userMenu and userMenu-expanderLink are shown by default. userMenu-expandedContent and userMenu-collapserLink are hidden by default.
What I am trying to do in jQuery is to slideDown the userMenu-expandedContentwhen a mouseover event occurs on userMenu-expander. All good there, this is my code:

$("#userMenu-expanderLink").mouseover(function() {
    $("#userMenu-expandedContent").stop().slideDown(200);
    $("#userMenu-expanderLink").hide();
    $("#userMenu-collapserLink").show();

    $("#userMenu").addClass("userMenu-expanded");
});

As you can see, I’m also hiding the expanderLink and showing the collapserLink; and also adding a class called userMenu-expanded to #userMenu. Until now, this code has no problems. Everything works well.

But now, I want that when the user has a mouseOut event on #userMenu.userMenu-expanded, effectively moving his mouse out of the #userMenu that is expanded, I want when that happens, the expandedContent is slideUp‘d, the expander and collapser links swapped, and the class removed. I know how to do that, but handling the event seems to be a problem.

Putting $("#userMenu.userMenu-expanded")... directly alongside the code I have of course does not work, since a div with such id and such class is only generated if the menu has been expanded, and the div’s class is removed once the menu is collapsed. I don’t directly use a mouseover/mouseout event on one object because I want the collapsing to be triggered only when the user takes his mouse out of the menu, not the expander link.

So, here’s my problem. How can I get such mouse out event? I have tried adding the event handler in the callback of .addClass, but no avail, it would basically permanently close that expanded menu (basically I can’t ever expand it again until I reload the page).

How can this be done? I’m not very experienced with jQuery, so a detailed answer would be most appreciated. I’m more interested on how can this be done rather than just accomplishing it, I want to learn ^_^.

Thanks!

  • 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-24T10:56:32+00:00Added an answer on May 24, 2026 at 10:56 am

    I have found a correct way to do this. This is my final implementation.

    $(document).ready(function() {
    // UserMenu Expander, which is also a form of drop down
    $("#userMenu-expander").mouseenter(function() {
        //alert("Usermenu expanding…");
        $("#userMenu-expandedContent").slideDown(200, function() {
            $("#userMenu").addClass("userMenu-expanded");
        });
        $("#userMenu-expanderLink").hide();
            $("#userMenu-collapserLink").show();
    });
    
    $("#userMenu.userMenu-expanded").live('mouseleave', function() {
        //alert("Usermenu de-expanding…");
        $("#userMenu-expandedContent").slideUp(200);
        $("#userMenu-expanderLink").show();
            $("#userMenu-collapserLink").hide();
    
        $("#userMenu").removeClass("userMenu-expanded");
    });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the title might be a little bit confusing, let me explain, ;) I have
The title is a little confusing so I will explain. I have the following
Ok, that title is going to be a little bit confusing. Let me try
Maybe the title is a little bit obscure, but let me explain... In a
Was little bit difficult to formulate the title for my question since is kind
Sorry the title is a little bit long. So I have a twitter account
this is a little bit complicated question. I want to achieve the following behaviour
My question title sounds a little bit difficult - sorry. I'm new in MEF
The title sucks, I'm sorry. It takes a little bit to setup my problem,
I am having a little bit trouble with the following. I have multiple form

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.