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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:33:54+00:00 2026-06-16T11:33:54+00:00

I have jquery menu with accordion and toggle effect. But it works with bugs:

  • 0

I have jquery menu with accordion and toggle effect. But it works with bugs: sometimes it closes all elements.

Can you help to do it best?

HTML:

<ul id="accordion">
    <li>
        <a href="#">Level 1</a>
        <ul>
            <li><a href="#">11</a></li>
            <li><a href="#">12</a></li>
        </ul>
    </li> 
     <li>
        <a href="#">Level 2</a>
        <ul style="display: none;">
            <li><a href="#">21</a></li>
            <li><a href="#">22</a></li>
        </ul>
    </li> 
</ul>

JS:

var sel = '#accordion'
$(sel + ' li a').toggle(
        function() {
            var checkElement = $(this).next();
            if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
                return false;
            }
            if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
                $(sel + ' ul:visible').slideUp('normal').removeClass('selected');
                checkElement.addClass('selected').slideDown('normal', function() {

                });
                return false;
            }
        },
        function() {
            $(sel + ' ul:visible').removeClass('selected').slideUp('normal', function() {

            });
        }
    );​

DEMO: http://jsfiddle.net/uG6zB/11/

  • 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-16T11:33:56+00:00Added an answer on June 16, 2026 at 11:33 am

    i looked over your code and I am not sure toggle is the best function for what you are trying to do, as I understand it.

    I changed toggle to click and I changed your logic just a little.

    the javascript looks like this now:

    var sel = '#accordion'
    $(sel + ' li a').click( function(){
        var checkElement = $(this).next();
        if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
            checkElement.slideUp('normal').removeClass('selected');
        }
        else if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
            $(sel + ' ul:visible').slideUp('normal').removeClass('selected');
            checkElement.addClass('selected').slideDown('normal', function() {
    
            });
        }
    });
    

    With this javascript I was able to get the menus to go up and down with no quirky behavior.
    fiddle

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

Sidebar

Related Questions

I'd like to use something like jQuery's accordion menu, but have the triggered elements
I have a sidebar with collapsible menu it works fine but all the values
I have a menu (jquery-ui accordion with Html.ActionLink as menu options). How can I
I have a real simple jQuery accordion based on http://www.stemkoski.com/stupid-simple-jquery-accordion-menu/ Everything works fine but
I have a simple accordion menu working using jQuery but I'm having trouble styling
I am using jQuery to produce an accordion effect in a menu I have
I have a simple accordion-style menu which opens/closes its children with a help of
I have a jquery accordion style menu that I'd like to add some shortcut
I have created a jquery plugin to expand/collapse ul,li something like a accordion menu
where I am using Jquery UI. I have an accordion menu, which has multiple

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.