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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:40:42+00:00 2026-06-09T17:40:42+00:00

this is my first post here so I apologise in advance for any poor

  • 0

this is my first post here so I apologise in advance for any poor practise. I’ve been searching for a while, but haven’t come across a solution that fits my needs as yet – maybe I’m just doing it wrong. But here goes:

I’m building a site using the Big Cartel CMS and have delved into jQuery for the first time. I’m trying to create a horizontal and centred navigation menu that will display a sub-menu underneath, where appropriate. I’m fine with html and CSS, but am struggling with the jQuery.

The mark-up is as follows:

<nav>
    <ul id="mainNav">
        <li><a href="expand-the-sub-menu">Option 1</a>
            <ul id="option1Nav">
                <li><a href="somewhere">Option 1 Link 1</a></li>
                <li><a href="somewhere">Option 1 Link 2</a></li>
                <li><a href="somewhere">Option 1 Link 3</a></li>
                <li><a href="somewhere">Option 1 Link 4</a></li>
                <li><a href="somewhere">Option 1 Link 5</a></li>
            </ul>
        </li>
        <li><a href="expand-the-sub-menu">Option 2</a>
            <ul id="option2Nav">
                <li><a href="somewhere">Option 2 Link 1</a></li>
                <li><a href="somewhere">Option 2 Link 2</a></li>
                <li><a href="somewhere">Option 2 Link 3</a></li>
                <li><a href="somewhere">Option 2 Link 4</a></li>
                <li><a href="somewhere">Option 2 Link 5</a></li>
            </ul>
        </li>
        <li><a href="somewhere">Option 3</a></li>
        <li><a href="somewhere">Option 4</a></li>
        <li><a href="somewhere">Option 5</a></li>
        <li><a href="somewhere">Option 6</a></li>
    </ul>
</nav>

Whilst this format will not change, the number of options with sub-menus might (the client can change this at will).
My jQuery so far:

$('#mainNav ul').hide();
$('#mainNav li a').click(function(){
    $('#mainNav li:has("ul")').each(
        function(){
            $('nav').animate({bottom:'60px'},300,'easeOutQuint',function(){
            //Do magic stuff here - i.e. display the correct sub-menu.
            });
        }
    );
});

Currently, this targets all options (I can’t fathom why) when clicked, and I’ve still not got to the bottom of how to only display the appropriate sub-menu. Classes may be added to any html elements, if that helps to make things easier.

Thanks in advance!

  • 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-09T17:40:43+00:00Added an answer on June 9, 2026 at 5:40 pm

    How’s this:

    http://jsfiddle.net/qDX2q/3/

    $('#mainNav ul').hide();
    $('#mainNav a')
        .click(function()
               {
                    $('#mainNav ul').hide();
                    $(this).siblings("ul").show();
                    return false;
               });
    ​
    

    The things I think you were missing were:

    • Making sure you return false from the click event, so that bad url is not followed.
    • The this keyword. In the above code this is actually the anchor tag you are on. So you can just look for sibling uls and show them
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here, therefore apologize for any blunders. I'm developing a
This is my first post here so if I've been mistaken for my post
This is my first post here. I have been reading posts here since I
This is my first post here although I've come here for solutions very very
This is my first post here, but I've using this site regularly to help
This is my first post here on Stackoverflow, though over the years I've been
This is my first post here so kindly pardon any mistakes that I have.
This is my first post here, recently i have been working with JSF2.0 with
This is my first post here so go easy. I am trying to build
This is my first post here. I have a problem. I need to take

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.