Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Hiding menu items when menu item is clicked ...

Posted on 2013-01-21
Medium Priority
Last Modified: 2013-01-22
Hey all.

I have a menu that I created using various examples. It is a horizontal menu that goes several "layers" deep.

It all works fine except when I click on a menu option, it executes the code that is to be ran fine but the menu itself "stays visible".

in other words, if I hover over root element 1 and go down the list to element 5 and click it, the new code is ran but the menu itself stays visible until I "move the mouse off the menu".

Here is the CSS being used.

/* --------------------- */
/* BEGIN Navigation Menu */
/* --------------------- */
nav ul ul {
      display: none;

      nav ul li:hover > ul {
            display: block;

/* Level 1 */      
nav ul {
      background: #efefef;
      background: linear-gradient(top, #efefef 0%, #bbbbbb 100%);  
      background: -moz-linear-gradient(top, #efefef 0%, #bbbbbb 100%);
      background: -webkit-linear-gradient(top, #efefef 0%,#bbbbbb 100%);
      box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
      padding: 0 20px;
      border-radius: 10px;  
      list-style: none;
      position: relative;
      display: inline-table;
      background-color: #2e5568; /* change */
      nav ul:after {
            content: ""; clear: both; display: block;

nav ul li {
      float: left;
      background-color: #e7e7dd; /* change */
      nav ul li:hover {
            background: #4b545f;
            background: linear-gradient(top, #4f5964 0%, #5f6975 40%);
            background: -moz-linear-gradient(top, #4f5964 0%, #5f6975 40%);
            background: -webkit-linear-gradient(top, #4f5964 0%,#5f6975 40%);
      nav ul li:hover a {
            color: #2e5568; /* change */
            /* background-color: #2e5568;*/ /* change */
            background-color: #e7e7dd;
      nav ul li a {
            display: block; padding: .5em; /* change 25px 40px; */
            /* color: #757575; */
            color: #000; /* change - top menu text */
            font-weight: bold;
            font-size: 10pt;
            text-decoration: none;
/* Level 2 */      
nav ul ul {
      background: #5f6975;
      border-radius: 0px; padding: 0;
      position: absolute; top: 100%;
      nav ul ul li {
            float: none;
            /* border-top: 1px solid #6b727c; change */
            border-bottom: 1px solid #575f6a;
            position: relative;
            nav ul ul li a {
                  padding: .5em; /* change 15px 40px; */
                  color: #fff;
                  nav ul ul li a:hover {
                        /* background: #4b545f; */
                        background: #d5d5cc; /* change */

/* Level 3 */
nav ul ul ul {
      position: absolute; left: 100%; top:0;
      nav ul ul ul li a {
            width: 10em;
            padding: .5em; /* change 15px 40px; */
            color: #fff;
/* ------------------- */
/* END Navigation Menu */
/* ------------------- */

I think I can get around it by using a "hack" but I would rather it be "graceful".

Any help would be greatly appreciated.
Question by:Webspeeder
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 53

Expert Comment

ID: 38803155
Of course it stays visible; you are still hovering.  If you don't want it that way then uses classes and use the onclick of the element to swap the classes and the mouseout event to restore the class so it is still usable if you hover again.


Author Comment

ID: 38803184
This is the issue. I've used classes to "hide" the ul li elements, but then they are no longer visible.

I can add the on.(click) and have it triggered, the problem is that I don't how to "hide" the menu items and still have them available.

Author Comment

ID: 38803189
OK, I think I see. I need to manually do what the CSS is doing in the line nav ul li:hover > ul. Right?
LVL 53

Accepted Solution

COBOLdinosaur earned 2000 total points
ID: 38803330
Something like that.  The lines of that kind of menu mess is something I never look at.  Drop down menus are, IMO lame, and I never use them because they breaks too easily, add zero usability, are badly implement most of the time, and force the user translate on the fly.

In any case all you have to do is add a class to the element with their default display property and when the get click, change the the class to one with property display:none. Then when the mouseout fires set them back to the original class.


Author Comment

ID: 38805703
I got it. The issue I was having was that I defined the events on the menu on document ready but the menu system itself is dynamically generated, after the the events were defined.

I defined the events after the menu is generated and all is working now.

Thanks for your input.

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question