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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:46:38+00:00 2026-06-01T18:46:38+00:00

Currently I’m able to click on a title and then the information relating to

  • 0

Currently I’m able to click on a title and then the information relating to the title is shown. If another title is selected then it is opened either below or above the previous open title, if the title is clicked a second time then they are hidden.
What I’m trying to do is, if a title is already open, upon clicking on another title it would hide the previous and show the most recently clicked.

The javascript I’m currently working with is the following

<script type="text/javascript">
 function unhide(divID) {
    var item = document.getElementById(divID);
    if (item) {
        item.className=(item.className=='hidden')?'unhidden':'hidden';
    }
 }

 function hide(divID) {
    var item = document.getElementById(divID);
    if (item == 'element_name') {
        item.className=(item.className=='hidden');
    }
 }
  • 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-01T18:46:39+00:00Added an answer on June 1, 2026 at 6:46 pm

    Suggestion #1

    Give all of the title elements a common class name, e.g. title, then use document.getElementsByClassName('title') to find all of the title elements, and hide them all before “unhiding” the clicked title, if the clicked title element is hidden.

    That being said, you’ll need to modify the two functions you wrote to accommodate multiple classes in an element. You can easily set multiple class names via element.className = 'unhidden title', but your code will be rather inflexible. Your code will quickly become unwieldy as you try to modify your list of class names via the String#split method, looping through the classes to find and delete the hidden or unhidden classes.

    Suggestion #2

    Do not to use an unhidden class. Presumably, your unhidden class is defined as follows:

    .unhidden {
      display: block;
    }
    

    This class becomes much less useful if you have inline elements as well that you want to unhide because you’ll need another class:

    .unhidden-inline {
      display: inline;
    }
    

    If you simply define:

    .hidden {
      display: block;
    }
    

    and add or remove the hidden class to hide or show the element, then you can avoid this issue altogether. You’ll still have the issue of dealing with multiple class names in an element, however.

    Suggestion #3 (ideal)

    Use jQuery or Zepto.js to handle DOM traversal and manipulation, it will make your life much easier. You’ll no longer need to manipulate classes at all in this case, you can simply hide and show the elements directly with convenience methods. Include jQuery:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    

    Assuming the following markup:

    <ul>
      <li class="title">
        Title 1
        <div class="description">Best. Title. Ever.</div>
      </li>
      <li class="title">
        Title 2
        <div class="description">Second best title</div>
      </li>
      <li class="title">
        Title 3
        <div class="description">Worst. Title. Ever.</div>
      </li>
    </ul>
    

    and the following css:

    <style type="text/css">
      .description {
        display: none;
      }
    </style>
    

    you can do the following to accomplish your goal in a flexible manner:

    <script type="text/javascript">
      $('.title').click(function(event){
        currentDescriptionElement = $('.description', this); // this refers to the clicked DOM element in this context
        isHidden = currentDescriptionElement.is(':hidden');
    
        $('.title .description:visible').hide(); // hide all visible description elements
    
        if (isHidden)
          currentDescriptionElement.show();
      })
    </script>
    

    I hope this helps, good luck!

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

Sidebar

Related Questions

Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently I have a UITableview, I have enough data that cannot be shown entirely
Currently I have alot of information that are in several different divs. I want
Currently I'm able to post mesages and pictures to my wall using my app,
Currently, the .NET Framework 4.5 runs only on Windows 7 and above : Operating
Currently I am using LinkedList to add all the Command information. How can I
Currently i applied a DatePicker into my application and when i click the Button
Currently I am using HTML files for parts of my user interface. I display
currently, I`m implementing a map App with Mono4Droid and there I`m using a WebView
Currently I'm starting a new Activity and calling finish on a current one. Is

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.