Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question adapt this for multiple div's

    PHP Code:
    function ToggleNav() {
    if (
    document.getElementById('nav').style.display=='none') {
    document.getElementById('nav').style.display='';
    document.getElementById('hide').style.display='';
    document.getElementById('show').style.display='none';
    } else {
    document.getElementById('nav').style.display='none';
    document.getElementById('hide').style.display='none';
    document.getElementById('show').style.display='';
    }

    I have the that code but I want to adatp this code for multiple div's (like id="nav1", id="nav2"........) How I can make that?

    Best Regards

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function ToggleNav(zxcgrp,zxcid){
     var zxcobj=document.getElementById(zxcid)
     if (!window[zxcgrp]){ window[zxcgrp]=null; }
     if (window[zxcgrp]){ if (window[zxcgrp]!=zxcobj){ window[zxcgrp].style.display='none'; } }
     zxcobj.style.display=(zxcobj.style.display=='none')?'':'none';
     window[zxcgrp]=zxcobj;
    }
    </script>
    
    </head>
    <body>
    <input type="button" name="" value="Show 123" onclick="ToggleNav('grp1','main');"/>
    <input type="button" name="" value="Show ABC" onclick="ToggleNav('grp1','results');" />
    
       <div id="main" style="display:none;" >123</div>
       <div id="results" style="display:none;">ABC</div>
    <br />
    <br />
    <input type="button" name="" value="Show 123" onclick="ToggleNav('grp2','main1');"/>
    <input type="button" name="" value="Show ABC" onclick="ToggleNav('grp2','results1');" />
    
       <div id="main1" style="display:none;" >123</div>
       <div id="results1" style="display:none;">ABC</div>
    </body>
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thank's That Works!
    Last edited by urgido; 08-10-2006 at 11:54 AM.

  • #4
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    mmm... But I how do I leave the phrase "HIDE" to hide and "SHOW" to show?


  •  

    Posting Permissions

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