Showing right sub-ul of parent ul menu

Posted by Micke on Stack Overflow See other posts from Stack Overflow or by Micke
Published on 2010-03-30T08:15:59Z Indexed on 2010/03/30 9:03 UTC
Read the original article Hit count: 512

Hello, i have this html menu:

      <ul id='main'>
        <li class='active current' id='lighty'>
          <a href='/'>Lighty</a>
          <ul>
            <li class='sub'>
              <a href='/'>Hem</a>

            </li>
          </ul>
        </li>
        <li id='community'>
          <a href='/community'>Community</a>
        </li>
      </ul>

And this jquery:

        $("#menu ul > li").mouseenter(function(){
         id = $(this).attr("id");
         $("#menu #main li").removeClass("active");
         $(this).addClass("active");
        }).mouseleave(function(){
         id = $(this).attr("id");
         menu.timers[id] = setTimeout(function(){$("#menu #main li#"+id).removeClass("active");}, 2000);
        });

What i am trying to acomplish is that when i hover one of the li's in the main ul the child ul of that li should be displayed. and when i move the mouse out of the li or the child ul the menu should be visible for 2 seconds. It works through the main li button but if on the child ul and move out it just disapears, it doesnt wait for two seconds.

The waiting two seconds is so you can go in to the menu if you accidentaly move the mouse out of it.

Can anybody help me to fix this error? Maybe you have a better solution?

Here is also a screenshot on how the menu looks if it helps: screen shot under or click hereScreenshot

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-selectors