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

The Archive Base Latest Questions

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

I have created this code to do a very nice, elegant pull-down sidebar navigation

  • 0

I have created this code to do a very nice, elegant pull-down sidebar navigation system – and I am including a jsFiddle as well for convenience.

http://jsfiddle.net/ciel/pC34j/

It works almost exactly like I want. This is the required functionality.

  • Top Level Items, when clicked, should slide their menus into view (Perfect)
  • Top Level Items, when clicked, should close all other open top level items (Perfect)
  • Top Level Items, when clicked, if opened, should close again (Seeming to Work)
  • Child Menus should be supported, which have all of this same functionality (FAIL!)

The problem I am having is with the child menus. On the fiddle, if you click on Top Level (3) you will see several child menus. Clicking on one causes the entire menu to collapse again, and you must click on the Top Level (3) again to open it.

Any ideas how I can address this issue? The link to jsfiddle is above, but I am putting it on the question as well.

Javascript

(function($) {
    $.fn.drawer = function(options) {
        // Create some defaults, extending them with any options that were provided
        var settings = $.extend({
            openClass: 'open'
        }, options);

        var open = function(e) {
            // mark this menu as open
            $(e).addClass(settings.openClass);

            // retrieve the appropriate menu item
            var $menu = $(e).children(".dropdown-menu, .sidebar-dropdown-menu");

            // slide down the one clicked on.
            $menu.slideDown(100);
            $menu.addClass('active');
        };

        var close = function(e) {
            console.log("closing", e);
            $(e).removeClass(settings.openClass);
            // retrieve the appropriate menu item
            var $menu = $(e).children(".dropdown-menu, .sidebar-dropdown-menu");
            // slide down the one clicked on.
            $menu.slideUp('fast');
            $menu.removeClass('active');
        };

        return this.each(function() {
            $(this).on('click', function(e) {
                // transform the selector into a 'className'
                var $className = $('.' + settings.openClass);
                var $node = $(this); // the current node
                var $target = $(e.target); // the actual DOM target
                // examine all existing dropdown menus that are
                // currently open, and close them - excluding the
                // current one.
                $className.not($(this)).each(function() {
                    close($(this));
                });

                if ($target.hasClass("root") && $node.hasClass(settings.openClass)) {
                    close($(this));
                }
                else {
                    // open the selected dropdown menu
                    open($(this));
                }

                // prevent default event propogation
                e.preventDefault();
            }).on("mouseleave", function() {
                $(this).children(".dropdown-menu").hide().delay(300);
            });

        })
    };

})(jQuery);
$(document).ready(function() {
    $(".dropdown > a").addClass("root");
    $('[data-role="sidebar-dropdown"]').drawer({
        openClass: 'sidebar-dropdown-open'
    });
    $('[data-role="sidebar-sub-dropdown"]').drawer({
        openClass: 'sidebar-sub-dropdown-open'
    });
});​

HTML

<ul>
    <li class="dropdown" data-role="sidebar-dropdown">
        <a href="pages/....html" class="remote"><i class="icon-libreoffice"></i>Top Level (A)</a>
        <ul class="sub-menu light sidebar-dropdown-menu">
            <li><a class="remote" href="pages/....html">Sub Link</a></li>
            <li><a class="remote" href="pages/....html">Sub Link</a></li>
            <li><a class="remote" href="pages/....html">Sub Link</a></li>
        </ul>
    </li>
    <li class="dropdown" data-role="sidebar-dropdown">
        <a href="pages/.....html" class="remote"><i class="icon-book"></i>Top Level (B)</a>
        <ul class="sub-menu light sidebar-dropdown-menu">
            <li><a href="pages/....html" class="remote">Sub Link</a></li>
            <li><a href="pages/....html" class="remote">Sub Link</a></li>
            <li><a href="pages/....html" class="remote">Sub Link</a></li>
            <li><a href="pages/....html" class="remote">Sub Link</a></li>
            <li><a href="pages/....html" class="remote">Sub Link</a></li>
            <li><a href="pages/....html" class="remote">Sub Link</a></li>
            <li><a href="pages/....html" class="remote">Sub Link</a></li>
        </ul>
    </li>
    <li class=" dropdown" data-role="sidebar-dropdown">
        <a href="pages/....html" class="remote"><i class="icon-trophy"></i>Top Level (C)</a>
        <ul class="sub-menu light sidebar-dropdown-menu">
            <li class="dropdown" data-role="sidebar-sub-dropdown">
                <a href="pages/....html" class="remote">Sub Level (Alpha)</a>
                <ul class="sub-menu light sidebar-dropdown-menu">
                    <li>
                        <a href="pages/....html" class="remote">Sub-Sub Link
                        </a>
                    </li>
                    <li>
                        <a href="pages/.....html" class="remote">Sub-Sub Link
                        </a>
                    </li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                </ul>
            </li>
            <li class="dropdown" data-role="sidebar-sub-dropdown">
                <a href="pages/....html" class="remote">Sub Level (Beta)</a>
                <ul class="sub-menu light sidebar-dropdown-menu">
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                </ul>
            </li>
            <li class="dropdown" data-role="sidebar-sub-dropdown">
                <a href="pages/....html" class="remote">Sub Level (Gamma)</a>
                <ul class="sub-menu light sidebar-dropdown-menu">
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                </ul>
            </li>
            <li class="dropdown" data-role="sidebar-sub-dropdown">
                <a href="pages/....html" class="remote">Sub Level (Delta)</a>
                <ul class="sub-menu light sidebar-dropdown-menu">
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                </ul>
            </li>
            <li class="dropdown" data-role="sidebar-sub-dropdown">
                <a href="pages/....html" class="remote">Sub Level (Kappa)</a>
                <ul class="sub-menu light sidebar-dropdown-menu">
                    <li><a href="pages/....html" class="remote">Sub-Sub Link</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

​

Relevant CSS (Just makes it look right)

ul > li > a {
    font-size: 1.1em;
}

.dropdown, .dropdown > a {
    font-weight: 600 !important;
}

a {
    font-family: 'Segoe UI', 'Open Sans', Verdana, Arial, Helvetica, sans-serif;
    font-weight: 400;
    font-size: 11pt;
    letter-spacing: 0.01em;
    line-height: 14pt;
    color: black;
    display: block;
    width: 100%;
    padding: 5px 20px 5px 10px;
    white-space: nowrap;
    font-size: 14px;
    cursor: pointer;
}

a, .link {
    font-family: 'Almendra', 'Segoe UI', 'Open Sans', Verdana, Arial, Helvetica, sans-serif;
    font-weight: 400;
    font-size: 11pt;
    color: #2E92CF;
    text-decoration: none;
}

*, ::after, ::before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

ul > li.dropdown::after {
    content: "";
    display: block;
    position: absolute;
    top: 6px;
    left: 100%;
    margin-left: -20px;
    width: 16px;
    height: 16px;
    background: no-repeat;
    background-position: 0 -1586px;
    z-index: 200;
}

ul.sub-menu.light {
    background-color: #F9F9F9 !important;
}

ul.sub-menu {
    padding-top: 5px;
    padding-bottom: 5px;
}

.sidebar-dropdown-menu {
    display: none;
}

.page-sidebar ul {
    margin-left: 0;
    list-style: none;
    background-color: #EBEBEB;
}

ul ul {
    list-style-type: circle;
}

ul ul, ul ol, ol ol, ol ul {
    margin-bottom: 0 !important;
}

​

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

    You’re very nealry there. The problem is you have added the line:

    e.preventDefault();
    

    But to successfully stop the propagation as it says in your code comment you need to include:

    e.stopPropagation();
    

    Or simply return false; which will accomplish both. Here’s an updated jsFiddle: http://jsfiddle.net/pC34j/8/

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

Sidebar

Related Questions

I have created this Fiddle with this code: This is my problem I want
I have an array created with this code: var widthRange = new Array(); widthRange[46]
I have made this code to open a database(created in SQLite browser) stored in
All, I am trying to code a Connect4 game. For this, I have created
Magento has this very nice MVC system where modules can register their 'frontname' and
Well, here I continue, trying to learn this very nice language... So I previously
Im create this code to store page view in database, but i have problem
I have create a vcf file that contains contacts by using this code ContentResolver
I have this code to create an ATOM feed Dim xmlResult As New StringBuilder
I have this code to create a webapp in my server: import web urls

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.