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

  • Home
  • SEARCH
  • 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 8971519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:58:40+00:00 2026-06-15T17:58:40+00:00

I have created a simple jQuery Menu that expands on hover however unless the

  • 0

I have created a simple jQuery Menu that expands on hover however unless the user hovers over another menu item or clicks else where in the page, the menu items do not get hidden. When you load another page using the links on the menu the page opens and leaves the menu expanded. How can I fix this? A fiddle with all the html and css can be found here. My jQuery code is here

                $(document).ready(function(){

                    $("#header_nav > li ").addClass("level1");
                    $("#header_nav  > li > ul > li ").addClass("level2");
                    $("#header_nav  > li > ul > li > ul > li ").addClass("level3");

                    $(".level1").live("hover",function(){

                        $(".level1").removeClass("main_menu_hover");
                        $(this).addClass("main_menu_hover");


                        var numberofChildren = $(this).find("> ul").children().length;

                        if(numberofChildren != 0){
                            // Section 1
                            $(".level1").removeClass("active_main_menu");
                            $(this).addClass("active_main_menu");

                            // Section 2
                            $(".level1").find("ul").css("display","none");
                            $(this).find(" > ul").css("display","block");

                            // Section 3
                            $(".level2").removeClass("active_first_element");
                            $(".level2").removeClass("active_last_element");
                            $(".level2").removeClass("active_only_element");

                            // Section 4
                            if(numberofChildren == 1){
                                $(this).find("ul li:first").addClass("active_only_element");
                            }else{
                                $(this).find("ul li:first").addClass("active_first_element");
                                $(this).find("ul li:last-child").addClass("active_last_element");
                            }

                            // Section 5
                            $(".level2 a").removeClass("sub_active");
                            $(".level2").removeClass("menu_hover");


                        }else{
                            // Section 6
                            $(".level1").find("ul").css("display","none");
                            $(".level1").removeClass("active_main_menu");

                        }

                    });

                    $(".level2").find(".arrow-right").attr("href","javascript:void(0);");

                    $(".level2 > a").live("hover",function(e){
                        $("li").removeClass("menu_hover");
                        $(this).parent().addClass("menu_hover");
                        e.preventDefault();
                    });

                    $(".level2 a").live("click",function(){
                        $("li").removeClass("menu_hover");

                        if($(this).hasClass("sub_active")){
                            $(this).removeClass("sub_active");
                            $(".level2 > ul").slideUp();
                        }else{
                            $(".level2 ul").slideUp();
                            $(".level2 a").removeClass("sub_active");
                            $(this).addClass("sub_active");
                            $(this).parent().find("ul").slideDown();
                        }
                    });





                    $(".level3 a").live("hover",function(){
                        if(!($(this).parent().hasClass("accordian_element_hover"))){
                            $(this).parent().removeClass("level3").addClass("accordian_element_hover");
                        }
                    });
                    $(".accordian_element_hover a").live("hover",function(){
                        $(this).parent().addClass("level3").removeClass("accordian_element_hover");
                    });


                });
  • 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-15T17:58:41+00:00Added an answer on June 15, 2026 at 5:58 pm

    You can try something like this:

    $(".level1").live("mouseover mouseout", function(event) {
        if (event.type == 'mouseover') {
                //Your old menu code
        } else {
            $(this).attr("class","level1");
            $(this).find("ul").hide();
        }
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a simple jQuery post that returns data every time an user types
I have created a custom jQuery plugin that does some simple image resizing for
I have created a simple page that use jQuery, so include jquery.min.js. But I
I have created a simple JQuery script with hovering effect on some links. The
I have created a navigation menu where, when clicking on a link, a jquery
Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created an HTML page which uses simple CSS (no javascript) for menu
So I created a simple menu for a small project I have. When people
I've created a simple auto-complete control using JQuery UI. I have a default value
I'm using jQuery to create a simple, but large dropdown menu. I have some

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.