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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:27:33+00:00 2026-06-13T21:27:33+00:00

I have some menu with structure like this: <ul id=menu> <li><a href=#><span>First level link

  • 0

I have some menu with structure like this:

<ul id="menu">
    <li><a href="#"><span>First level link 1</span></a>
        <ul>
            <li><a href="#"><span>Child link 1</span></a></li>
            <li><a href="#"><span>Child link 2</span></a></li>
        </ul>
    </li>
    <li><a href="#"><span>First level link 2</span></a>
        <ul>
            <li><a href="#"><span>Child link 2</span></a></li>
            <li><a href="#"><span>Child link 2</span></a></li>
        </ul>
    </li>
</ul>

It need to show only first level ul li, its ok, but then it needs to show by on click second level links. And i cant usw id or rel attr in ul or li – this is my problem to catch child .

My code is like:

var menuRaw = $("ul#menu > li:lt(5)");

    menuRaw.click(function(e){
        e.preventDefault();

        var menuItem = $(this);

        menuRaw.removeClass("selected");
        menuItem.addClass("selected");

        $('#menu ul').hide();
        menuItem.find("ul").show();
    }

And it works but e.preventDefault() is blocking all links in menu (but on second level links needs to be working links as normally they do)

Sorry for my English, and this is first question on stackoverflow.

  • 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-13T21:27:33+00:00Added an answer on June 13, 2026 at 9:27 pm

    You can achieve this by checking if the clicked li has any ul‘s nested within it.

    $('#menu li').click(function(e) {
    
      $this = $(this);
      e.stopPropagation(); 
    
      if ($this.has('ul').length) {
        e.preventDefault();
        $('ul', this).fadeToggle();
      } 
    
    });
    

    Here’s a demo

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

Sidebar

Related Questions

I have some code that first selects an option value in a dropdown menu
I have a jquery accordion style menu that I'd like to add some shortcut
I have a website with a menu. To generate the menu, I need some
I have something like this: public abstract class Menu { public Menu() { init();
I have some mega menu style menus on a site I maintain. These are
I have some jquery which will calculate the items in my menu and assign
I have some simple markup: <table> <tr> <td>Menu Item</td> </tr> </table> <div> <table> <tr>
I have the following two links in my main menu, and I have some
I have a Servlet called Menu that generates some html and a dynamic menu,
I have a drop down menu which fills with some doc names. Now when

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.