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>
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]
Comment