Is Layer hidden?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ckerns@fuse.net

    Is Layer hidden?

    How can I check to see if a layer is visible? I have four layers and
    I want to check each to use in an if...then...els e statement.

    tia


  • RobG

    #2
    Re: Is Layer hidden?

    ckerns@fuse.net wrote:[color=blue]
    > How can I check to see if a layer is visible? I have four layers and
    > I want to check each to use in an if...then...els e statement.
    >[/color]

    I guess by 'layer' you mean an element like a <div>. You can get the
    value of an element's visibility property using its style object:

    var ele = <some element>;
    var eleVisibility = ele.style.visib ility;

    Most (all?) elements are visible by default, so if it hasn't been set
    then from the above eleVisibility will be ''. If it has been set to
    any other value, then that will be returned.

    Some play code below:

    <script type="text/javascript">
    function showDivVis(){
    var d = document.getEle mentsByTagName( 'div');
    if (d[0].style){
    var msg=[], i=d.length, id;
    while (i--){
    id = d[i].id;
    if ( id && /div-/.test(id) ){
    msg[i] = id + ': ' + d[i].style.visibili ty;
    }
    }
    alert(msg.join( '\n'));
    }
    }
    </script>

    <div style="visibili ty: hidden" id="div-1">Div 1</div>
    <div style="visibili ty: visible" id="div-2">Div 2</div>
    <div style="visibili ty: hidden" id="div-3">Div 3</div>
    <div id="div-4">Div 4</div>
    <input type="button" value="Show div visibility" onclick="
    showDivVis();">

    --
    Rob

    Comment

    • RobG

      #3
      Re: Is Layer hidden?

      RobG wrote:[color=blue]
      > ckerns@fuse.net wrote:
      >[color=green]
      >> How can I check to see if a layer is visible? I have four layers and
      >> I want to check each to use in an if...then...els e statement.
      >>[/color]
      >
      > I guess by 'layer' you mean an element like a <div>. You can get the
      > value of an element's visibility property using its style object:
      >
      > var ele = <some element>;
      > var eleVisibility = ele.style.visib ility;
      >
      > Most (all?) elements are visible by default, so if it hasn't been set
      > then from the above eleVisibility will be ''. If it has been set to
      > any other value, then that will be returned.[/color]

      Should have mentioned here that if the visibility has been set by CSS
      style sheet then visibility will return '' regardless of what it has
      been set to (unless it has been overridden by an in-line style).

      In that case, you need to use getComputedStyl e and the IE equivalent
      getCurrentStyle to determine the visibility (or you could fish
      through the style sheet(s) looking for the appropriate rule, but I
      think that would be far more code than is reasonable).

      Do a search of this newsgroup to find examples of getComputedStyl e
      and getCurrentStyle .

      The simplest method is to set visibility in-line and go from there if
      that suits.
      [color=blue]
      >
      > Some play code below:
      >
      > <script type="text/javascript">
      > function showDivVis(){
      > var d = document.getEle mentsByTagName( 'div');
      > if (d[0].style){
      > var msg=[], i=d.length, id;
      > while (i--){
      > id = d[i].id;
      > if ( id && /div-/.test(id) ){
      > msg[i] = id + ': ' + d[i].style.visibili ty;
      > }
      > }
      > alert(msg.join( '\n'));
      > }
      > }
      > </script>[/color]

      <style type="text/css">
      #div-3 {visibility: hidden;}
      </style>
      [color=blue]
      > <div style="visibili ty: hidden" id="div-1">Div 1</div>
      > <div style="visibili ty: visible" id="div-2">Div 2</div>[/color]

      <div id="div-3">Div 3</div>
      [color=blue]
      > <div id="div-4">Div 4</div>
      > <input type="button" value="Show div visibility" onclick="
      > showDivVis();">[/color]


      --
      Rob

      Comment

      Working...