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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:01:54+00:00 2026-05-25T02:01:54+00:00

Any help on this problem would be appreciated. I have a main navigation like

  • 0

Any help on this problem would be appreciated. I have a main navigation like so:

<ul>
  <li><a href="">Nav 1</a></li>
  <li><a href="">Nav 2</a></li>
  <li><a href="">Nav 3</a></li>
  <li><a href="">Nav 4</a></li>
 </ul>

Somewhere below there is a content div like so:

<div id="content">
  <div class="block-1">
    <p>Lorem ipsum</p>
  </div>
  <div class="block-2">
    <p>Lorem ipsum</p>
  </div>
  <div class="block-3">
    <p>Lorem ipsum</p>
  </div>
  <div class="block-4">
    <p>Lorem ipsum</p>
  </div>
</div>

The #content div has display:none; set in the stylesheet. As do each of the blocks inside it. When someone clicks a nav item I would like it to show the content container, with only that block the corresponds to it. Nav1 = block-1 etc… When you click another link it hides the other and shows the new selection.

Any ideas?

  • 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-25T02:01:55+00:00Added an answer on May 25, 2026 at 2:01 am

    I’ve written a quick JSFiddle for you. Using jQuery’s .index() method, you can get the index of the clicked link, and use that to show the correct div. I’ve used a class in the following code to show/hide your div. You could replace this with an extra bit of logic to fade each div, for example.

    Another point to make is you don’t need the -1, -2, etc postfixes on the divs; index() and the :eq() selector handles this for you. I’ve changed your HTML slightly and here is the JS:

    JavaScript

    $(document).ready(function() {
        $("ul a").click(function() {
            var index = $(this).parent().index();
    
            $("div#content").find(".show").removeClass("show");
            $("div#content").find(".block:eq(" + index + ")").addClass("show");
        });
    });
    

    HTML

    <ul>
      <li><a href="#">Nav 1</a></li>
      <li><a href="#">Nav 2</a></li>
      <li><a href="#">Nav 3</a></li>
      <li><a href="#">Nav 4</a></li>
     </ul>
    
    <div id="content">
      <div class="block">
        <p>Lorem ipsum 1</p>
      </div>
      <div class="block">
        <p>Lorem ipsum 2</p>
      </div>
      <div class="block">
        <p>Lorem ipsum 3</p>
      </div>
      <div class="block">
        <p>Lorem ipsum 4</p>
      </div>
    </div>
    

    In response to the comments, here’s an update example that will hide every element when the first li is clicked. To make it more versatile, you could add a class (say, hideall) to the li and use .hasClass("hideall") inside the if() instead of index == 0, which checks to see if this is the first li in the list. JSFiddle here, JS below. I’ve edited the HTML in the Fiddle a little.

    $(document).ready(function() {
        $("ul a").click(function() {
            var index = $(this).parent().index();
            console.log(index);
    
            if(index == 0)
            {
                $("div#content > div").removeClass("show");
            }
            else
            {
                index--;
                $("div#content").find(".show").removeClass("show");
                $("div#content").find(".block:eq(" + index + ")").addClass("show");
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any help here would be greatly appreciated. I have this table hospital Nurse |
I would appreciate any help on this issue. Lets say I want to load
Any help most appreciated, this is driving me insane. I'm doing exactly what I
I'm very new to this, so any help is appreciated. I'll use the Dinners/RSVPs
When click a button,I want to popup a view form bottom,like this! Any help
I'd really appreciate any help with this problem. This is a much simplified version
I can't seem to find any help on this but under the Net tab
any help you can give is very gratefully accepted. I've been looking at this
I've been stuck on this issue for several days - any help is much
This is my first time on this site and I appreciate any help on

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.