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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:04:29+00:00 2026-05-27T15:04:29+00:00

again. I have a menu that I’m building. Everything works fine, except for the

  • 0

again. I have a menu that I’m building. Everything works fine, except for the fact that when I click one of the main categories, the page jumps back to the top. I would like to prevent this, but I’m worried that using preventDefault() will stop other links from loading correctly.

Here is the code..

jQuery

$(document).ready(function() {
    // Collapse everything but the first menu:
    $("#nav_menu > li > a").find("+ ul").slideUp(1);
    // Expand or collapse:
    $("#nav_menu > li > a").click(function() {
        $(this).find("+ ul").slideToggle("fast");
    });
});

The markup

<ul id="nav_menu">
    <li><a href="#">Main Cat 1</a>
        <ul>
            <li><a href="whatever.php">Subcat 1</a></li>
            <li><a href="whatever.php">Subcat 2</a></li>
        </ul>
    </li>
    <li><a href="#">Main Cat 2</a>
        <ul>
            <li><a href="whatever.php">Subcat 1</a></li>
            <li><a href="whatever.php">Subcat 2</a></li>
        </ul>
    </li>
</ul>

Any help on this would be appreciated! 🙂

  • 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-05-27T15:04:30+00:00Added an answer on May 27, 2026 at 3:04 pm

    You need to call the preventDefault function so that your a element doesn’t trigger the href.

    $(document).ready(function() {
        // Collapse everything but the first menu:
        $("#nav_menu > li > a").find("+ ul").slideUp(1);
        // Expand or collapse:
        $("#nav_menu > li > a").click(function(e) {
            e.preventDefault();
            $(this).find("+ ul").slideToggle("fast");
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdown menu that works fine, but I would like it so,
Background: I have a dropdown menu that basically works the same as the one
Me again... I have an XML File that contains different categories which I would
I have a menu bar that displays a set of categories in an upper
I have an accordion menu working on the page, but when I click one
I have jquery menu that on click shows specific div element. I wonder if
I have a simple search box that it hidden until hover(over) and hides again
I want to have a menu display that accepts user input. However, I want
I have an accessibility skip nav menu that uses named anchors to jump to
I have problems adding panorama items through code. Here is test xaml that works.

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.