Results 1 to 2 of 2

Thread: Open hidden layers code is making me click twice to open

  1. #1
    Join Date
    Jan 2009
    Posts
    82
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Open hidden layers code is making me click twice to open

    I have this code to show and hide layers that are all initially hidden.

    It only works if you open and close layer 1 and then go to open layer 2.

    The problem is I'm using this for multiple layers so when you open layer 1 and try to open layer 2 it makes you click twice for some reason even though it's not closing layer 1.

    I don't want it to close the first one anyway, but I want it to go smooth, like open layer one and open layer 2.


    Code:
    <script type="text/javascript">
    function toggleLayer( whichLayer )
    {
    var elem, vis;
    if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
    else if( document.all ) // this is the way old msie versions work
    elem = document.all[whichLayer];
    else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
    vis.display = (vis.display==''||vis.display=='block')?'none':'block';
    }
    </script>
    
    
    
    <a href="javascript:;" onClick="showhide('layerone');return false;">show it</a>
    <div id="layerone" style="display: none;">layer 1</div>
    
    
    <a href="javascript:;" onClick="showhide('layertwo');return false;">show it</a>
    <div id="layertwo" style="display: none;">layer 2</div>

  2. #2
    Join Date
    Jan 2009
    Posts
    82
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    It seems to be working now. I'm double checking. I think I was using a different script that was causing the error

Bookmarks

Posting Permissions

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