SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict djh's Avatar
    Join Date
    Apr 2000
    Location
    Long Beach, CA
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Turn every other layer to hidden

    I have this bit of javascript:
    Code:
    function toggleVisible(divname) {
     divstyle = getDivStyle(divname);
     if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
       divstyle.visibility = 'hidden';
     } else {
       fixPosition(divname);
       divstyle.visibility = 'visible';
     }
    }
    The problem is I need this function to turn all other visible layers to hidden.... Does someone know how to refer to all layers in a document and turn their visibility to hidden? I can then call that function from the above...

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this

    PHP Code:

    <p><div style="color:black;background:orange;" value="none">1</div></p>
    <
    p><div style="color:black;background:orange;">2</div></p>
    <
    p><div style="color:black;background:orange;">3</div></p>
    <
    p><div style="color:black;background:orange;">4</div></p>
    <
    p><div style="color:black;background:orange;">5</div></p>

    <
    input type="button" onclick="hiding(0)" value="click here"

    <
    script>

    function 
    hiding(donthide)
    {

        
    document.getElementsByTagName("div");

        for (
    a=0,b=x.length;a<=b;a++)
        {
            if     (
    a!=donthidex[a].style.display 'none';
            else    
    x[a].style.display 'block';
        }
    }

    </script> 

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this instead

    PHP Code:

    <p><div style="color:black;background:orange ;">1</div></p>
    <
    p><div style="color:black;background:orange ;">2</div></p>
    <
    p><div style="color:black;background:orange ;">3</div></p>
    <
    p><div style="color:black;background:orange ;">4</div></p>
    <
    p><div style="color:black;background:orange ;">5</div></p>

    <
    input type="button" onclick="hiding(2)" value="click here"

    <
    script>

    function 
    hiding(donthide)
    {

        
    document.getElementsByTagName("div");

        for (
    a=0,b=x.length;a<b;a++)
        {
            if     (
    a!=donthide-1x[a].style.display 'none';
            else    
    x[a].style.display 'block';
        }
    }

    </script> 
    Last edited by Andrew-J2000; Apr 23, 2002 at 04:09.

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, this is really similar to something i'm trying to do. how can you get this to work in netscape 4.x browsers?

    the above code works fine for me in IE

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    call these functions

    PHP Code:

    ns4 
    = (document.layers)? true:false
    ie4 
    = (document.all)? true:false

    function show(id) {
        if (
    ns4document.layers[id].visibility "show"
        
    else if (ie4document.all[id].style.visibility "visible"
    }

    function 
    hide(id) {
        if (
    ns4document.layers[id].visibility "hide"
        
    else if (ie4document.all[id].style.visibility "hidden"


  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not use a collection call?

    [/CODE]
    d=document.getElementsByTagName('DIV');
    vary=0;
    for (i=0;i<d.length;i++){
    vary=!vary;
    if (vary) d[i].style.visibility='hidden';
    }
    [/CODE]

    Something like that?


    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


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
  •