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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:11:48+00:00 2026-05-20T11:11:48+00:00

i use a simple bit of code to make a div collapse, this is

  • 0

i use a simple bit of code to make a div collapse, this is it:

<script language="JavaScript">
    <!--   
        function expand(param)   
        {   
            param.style.display=(param.style.display=="none")?"":"none";   
        }   
    //-->  
</script>

what code do i add to make it recognise when one div is open an collapse the previous div?
here’s the link I’d use:

<a href="javascript:expand(document.getElementById('div1'))">Link 1</a>  
      <div id="div1" width="300px" style="display:none"></div>

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-20T11:11:49+00:00Added an answer on May 20, 2026 at 11:11 am

    If you were willing to use jQuery, the selector of your interest is something along the lines of

    $('div#parent-container > div').filter(':visible');
    

    For example, if I were to demonstrate with next & previous, I would do it something like this. With targeted links it would work by appending ID’s to the divs and referencing those in the href attribute of `anchors’. (now included within example)


    Something to mess with:

    $(function(){
        //Reference Object
        var $divs = $('div > div');
        //Buffer for selected variable
        var $selected = 0;
        //Show first
        $divs.eq(0).show();
    
    
        $('#next').click(function(){
            //Update selected var
             $selected = $divs.filter(':visible');
            //Save next to variable
            var $next = $selected.next();
            //Change Visibility
            toggle($next);
            //Prevent Default
            return false;
        });
    
         $('#prev').click(function(){
            $selected = $divs.filter(':visible');
            var $prev = $selected.prev();
            toggle($prev);
            return false;
        });
    
        $('a').click(function(){
            $selected = $divs.filter(':visible');
            var selector = $(this).attr('href');
            if(selector == '#') return false;
            toggle( $( selector ) );
            return false;
        });
    
    
        var toggle = function($toggle){
         if(!$toggle.length) return false;
             $selected.hide();
             $toggle.show();   
         }
    });
    

    <!--Simple Implementation and dependancies-->
    <a id="prev" href="#">Prev</a>
    <a id="next" href="#">Next</a>
    <a href="#item-4">Show Item Four</a>
    
    <div>
        <div id="item-1">One</div>
        <div id="item-2">Two</div>
        <div id="item-3">Three</div>
        <div id="item-4">Four</div>
        <div id="item-5">Five</div
        <div id="item-6">Six</div>
    </div>
    

    div > div {
     font-size:5em;
     width:auto;
     text-align:center;
     padding:20px 0;   
     display:none;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings great SO comrades; I'm trying to use this code to make changes to
We use a simple object model for our low level networking code at work
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
There is a simple C++ method to use pattern matching on strings? The code
For use in a simple project of mine, I've hit a bit of a
I have to program a simple polymorphic engine. I use linux (32-bit) and i
I want to use the php simple HTML DOM parser to grab the image,
I'm looking for something simple to use where the grammar is easy to define.
My use case is very simple : I have a GUI application, and inside
Simple as the title states: Can you use only Java commands to take a

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.