CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    73

    hide/show divs simultaneously

    Hello all!
    I have 2 things that I want to show/hide using JS.

    Code:
    <html>
    <head>
    <title>Hidden Div</title>
    <script language="JavaScript">
    function showstuff(boxid){
       document.getElementById(boxid).style.visibility="visible";
    }
    
    function hidestuff(boxid){
       document.getElementById(boxid).style.visibility="hidden";
    }</script>
    </head>
    <body>
    
    	<a href="#" onclick="showstuff('one'); hidestuff('two');">Show ONE</a>
    	<a href="#" onclick="showstuff('two'); hidestuff('one');">Show TWO</a>
    
    <div id="one" style="display:none" >ONE.</div>
    <div id="two" style="display:none">TWO.</div>
    </body>
    </html>
    If I use it as it is I don't see anything!
    If I don't use style="display:none" inside the divs, I see them both initially and I can hide/show each one depending on which link I press. But the thing is that I need both divs to be hidden in the first place, and when I click on ONE, to show TWO, when I click on TWO to hide ONE and show TWO etc. Each time 1 div should be visible, depending on which link we press. The other must disappear.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: hide/show divs simultaneously

    Make one function that hides all the elements at the very beginning of the function. Then, proceed to show the proper element.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured