Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Thanked 0 Times in 0 Posts

    close one div when another opens

    I have a page with categories of images. When clicked, each image on the left opens a div with it's own gallery of thumbnails.


    Right now, to close a div, the category image has to be clicked a second time. How can I set it so that when one div opens, the other closes automatically? The client wants only one category displayed at a time.

    Any help would be appreciated.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,741 Times in 4,703 Posts
    Ugh...you are using *ANCIENT* code.

    That bit with layers only ever applied to Netscape 4 browser. And the need for document.all disappeared when MSIE 4 died. So that code is roughly 11 years old.

    I'm going to try coding this "blind". It would be easier to write if we changed some of the HTML on your page (and I really think it should be changed...you have all those <table>s in there all the time, even though their contents aren't being displayed), but let's start by just changing the JavaScript.

    See if this works:
    <!-- use the correct script tag -->
    <script type="text/javascript">
    // A list of all the affected <div>s by id
    var layerIds = ["com","irr","patios","ponds","res","walls"];
    function toggleLayer( which )
        for ( var d = 0; d < layerIds.length; ++ d )
            var id = layerIds[d];
            var div = document.getElementById(id);
            if ( id == which ) 
                div.style.display = ( div.style.display == "block" ) ? "none" : "block";
            } else {
                div.style.display = "none";


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts