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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:52:22+00:00 2026-06-09T04:52:22+00:00

I know. The title was a bit….hard to understand. I will see what I

  • 0

I know. The title was a bit….hard to understand. I will see what I can do to help you understand it.

Basically, what I’ve done for my personal site is the main navigation as the body of the web page. And when a link is clicked, it loads some hidden content, like so:

    $(document).ready(function(){
    $('li a#about-toggle').click(function(){
        $('li#about').animate({"height": "toggle", "opacity": "toggle"}, "slow").toggleClass("hidden"); 
    });
    $('li a#portfolio-toggle').click(function(){
        $('li#portfolio').animate({"height": "toggle", "opacity": "toggle"}, "slow").toggleClass("hidden"); 
    });
    $('li a#resume-toggle').click(function(){
        $('li#resume').animate({"height": "toggle", "opacity": "toggle"}, "slow").toggleClass("hidden"); 
    });
    $('li a#contact-toggle').click(function(){
        $('li#contactme').animate({"height": "toggle", "opacity": "toggle"}, "slow").toggleClass("hidden"); 
    });
});

This currently allows the visitor of the website to open all of the elements, which is not only visually displeasing, but creates a few bugs, but mostly visually displeasing.

My question is, with the code I have remaining as in-tact as possible, how would I make it so they can only have ONE open at a time?

Thanks in advance,
Jacob

EDIT:

    $(document).ready(function(){
    $('#about-toggle').click(function(){
        $("li.active").addClass("hidden");
        $('#about').animate({"height": "toggle", "opacity": "toggle"}, "slow").removeClass("hidden").addClass("active");
    });
    $('#portfolio-toggle').click(function(){
        $("li.active").addClass("hidden");
        $('#portfolio').animate({"height": "toggle", "opacity": "toggle"}, "slow").removeClass("hidden").addClass("active");
    });
    $('#resume-toggle').click(function(){
         $("li.active").addClass("hidden");
        $('#resume').animate({"height": "toggle", "opacity": "toggle"}, "slow").removeClass("hidden").addClass("active");
    });
    $('#contact-toggle').click(function(){
        $("li.active").addClass("hidden");
        $('li#contactme').animate({"height": "toggle", "opacity": "toggle"}, "slow").removeClass("hidden").addClass("active");
    });
});
  • 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-09T04:52:23+00:00Added an answer on June 9, 2026 at 4:52 am

    Put a common class on all the elements you want to close. Close them all except the one you clicked on and then open the one you clicked on. The ones that are already closed will do nothing when you close them again.

    Suppose you added the class togglers to each one, then you could do this and also shorten your jQuery into one block for all elements:

    $(document).ready(function(){
        $('#about-toggle, #portfolio-toggle, #resume-toggle, #contact-toggle').click(function(){
            // get the clicked on id and convert it to shortened form
            var id = this.id.replace(/\-.*$/, "");
            var item = $("#" + id);
            // toggle others that are open and toggle the current one
            $(".togglers").not(".hidden").add(item).animate({"height": "toggle", "opacity": "toggle"}, "slow").toggleClass("hidden"); 
        });
    });
    

    or, if you don’t put the common class on them, then you just have to list them all:

    $(document).ready(function(){
        $('#about-toggle, #portfolio-toggle, #resume-toggle, #contact-toggle').click(function(){
            // get the clicked on id and convert it to shortened form
            var id = this.id.replace(/\-.*$/, "");
            var item = $("#" + id);
            // toggle others that are open and toggle the current one
            $('#about, #portfolio, #resume, #contact').not(".hidden").add(item).animate({"height": "toggle", "opacity": "toggle"}, "slow").toggleClass("hidden"); 
        });
    });
    

    This implementation assumes that the .hidden class is applied to any items that are toggled closed and removed from any items that are open and the initial HTML state must match that.

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

Sidebar

Related Questions

I know title is a bit confusing ;D but basically what I want to
Ok I know the title is a bit confusing as I can't think of
I know the title is a bit weird, but I was unable to think
Horrible title I know, horrible question too. I'm working with a bit of software
I know the title is a little off, but it's hard to explain the
I know the title is a bit vague. But what I'm trying to achieve
I know the title's a bit wordy, but I don't know how else to
I know the title of this question is a bit confusing, but here it
I know the title is a little bit strange, but here is what the
I know the title sound confusing and thats because it is. its a bit

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.