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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:33:00+00:00 2026-06-15T17:33:00+00:00

I have a very basic accordion-like (http://jqueryui.com/accordion/) content display system. i’m new at this

  • 0

I have a very basic accordion-like (http://jqueryui.com/accordion/) content display system. i’m new at this and also stubborn, so I didn’t use the one provided.
here is the code:

        $(".listitem").click(function(){
            $("#info"+$(this).attr('id')).slideToggle("fast");
        });

<h3 class="listitem" id="1">title 1</h3>
<div id="info1">blah blah blah 1</div>

<h3 class="listitem" id="2">title 2</h3>
<div id="info2">blah blah blah 2</div>

all the list items have the id of a number 1-6 or whatever, and the hidden content has the id of “info” + the corresponding number. My question is how could I make it such that when a new item is clicked, it closes the previous one?

  • 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-15T17:33:01+00:00Added an answer on June 15, 2026 at 5:33 pm

    Keep track of which one’s open.

    (function() {
        var open = -1;
        $(".listitem").click(function() {
            var id = this.getAttribute("data-page");
            if( id != open) {
                $("#info"+id+", #info"+open).slideToggle("fast");
                open = id;
            }
        });
    })();
    
    <h3 class="listitem" data-page="1">title 1</h3>
    <div id="info1">blah blah blah 1</div>
    
    <h3 class="listitem" data-page="2">title 2</h3>
    <div id="info2">blah blah blah 2</div>
    

    Note that I have replaced your id attributes with data-page, since in HTML4 it is not valid to have an ID starting with a number and it’s inappropriate use of ID anyway. Additionally, I replaced the $(this).attr(...) with its vanilla JS equivalent for efficiency.

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

Sidebar

Related Questions

I have a very basic API in my app which also has an index
I have a Clojure network application, basic structure is like this: Server has one
I have very basic understanding problem of Content types. I went through lot of
Hi I have very basic question. I have view like below: def view1: dict
I am very new to Facebook applications and have very basic questions. I use
I have a very basic mysql table called memberships, that tracks which people belong
I have a very basic windows forms app, working in C#, and I was
I have a very basic app with two ignition-remoteimageviews (RIV) in them. The app
I have some very basic semaphore code that works great on Linux, but cannot
I have a very basic doubt regarding the method that gets executed when app

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.