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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:10:24+00:00 2026-06-13T11:10:24+00:00

I have a show/hide menu built. Which works great. But by default the menu

  • 0

I have a show/hide menu built. Which works great. But by default the menu is closed, again this is fine until the page is navigated to.

When the page is navigated to the a anchor is built with the class of “active”, What I would like to is check if “active” exsists with the menu and display that block based on that. So at least one menu is always open.

My current jQuery is as follows :

    $('.sub_menu').hide();
$('.clickable').toggle(function(){
    $(this).next('ul').slideToggle();
    $(this).css('background-position','0px -12px');
}, function()
{
    $(this).next('ul').slideToggle();
    $(this).css('background-position','0px 5px');       
});

if ($('ul.sub_menu li a').hasClass('active')) {
    $(this).css('display','block');
}

I have also made a jsFiddle

So I am targetting if the ul.sub_menu li a = active and if it is show the sub_menu.

But not having any luck with it. Thanks in advance

  • 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-13T11:10:25+00:00Added an answer on June 13, 2026 at 11:10 am

    The easiest approach to this is to check if ul.sub_menu contains an a.active. If so then set display: block. This can be done with the following code.

    $('.sub_menu').hide();
    $('.clickable').toggle(function (){
        $(this).next('ul').slideToggle();
        $(this).css('background-position', '0px -12px');
    }, function (){
            $(this).next('ul').slideToggle();
            $(this).css('background-position', '0px 5px');
    });
    
    $('ul.sub_menu').has('a.active').css('display', 'block');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div show hide function which is working fine. when I click
i have this show/hide menu. It is possibly this menu make with memory?( I
I am encountering an odd behavior using jQuery to show/hide a menu. I have
I have a menu with submenus that can be toggled (hide/show type deal). Is
I was hoping to use this with MvcSiteMapProvider to hide / show menu items
I have an action bar with a menuitem. How can I hide/show that menu
I'm writting script to hide/show menu but I get some troubles. function displayMenu() {
I have a menu item that I want to show/hide only if the user
New to jquery. The desire is to show/hide horizontal menu bar items. I have
I've written a cookie-based toggle show/hide menu. It remembers what was open/closed using the

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.