473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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...else statement.

tia
Jul 23 '05 #1
2 3149
ck****@fuse.net wrote:
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...else statement.


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.visibility;

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.getElementsByTagName('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.visibility;
}
}
alert(msg.join('\n'));
}
}
</script>

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

--
Rob
Jul 23 '05 #2
RobG wrote:
ck****@fuse.net wrote:
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...else statement.

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.visibility;

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.


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 getComputedStyle 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 getComputedStyle
and getCurrentStyle.

The simplest method is to set visibility in-line and go from there if
that suits.

Some play code below:

<script type="text/javascript">
function showDivVis(){
var d = document.getElementsByTagName('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.visibility;
}
}
alert(msg.join('\n'));
}
}
</script>
<style type="text/css">
#div-3 {visibility: hidden;}
</style>
<div style="visibility: hidden" id="div-1">Div 1</div>
<div style="visibility: visible" id="div-2">Div 2</div>
<div id="div-3">Div 3</div>
<div id="div-4">Div 4</div>
<input type="button" value="Show div visibility" onclick="
showDivVis();">

--
Rob
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard | last post by:
Can someone help me figure out how to show a hidden layer *ONLY* if the browser is IE for windows? I want it to remain hidden for everything else, Netscape, Opera, Mozilla and anything for Mac. ...
2
by: ckerns | last post by:
I have an asp/javascript page. The page has several hidden layers. When the user clicks a button, a layer becomes visible. How can I check the state of a layer to see if it is hidden or not in...
9
by: Hasan O. Zavalsiz | last post by:
Hi , i am trying to figure out which approach is better to use . let me explain the scenario. i am using the "Nortwind" database . in this database i have "Customers " table .The following is the...
3
by: Merlin | last post by:
Hi there, I am trying to create a form with an dynamic field that can be shown or hidden. As I saw for example on google it is possible with JS to show a layer and move the content underneath...
1
by: gammajonny | last post by:
Im 14 yrs old and just make web sites for fun really, i use html css and java script at the moment but im just starting java. I live in Exeter in the uk. That me basicly. My first question is- ...
2
by: lee | last post by:
Hello I need to hide a layer after a set time when the page loads. Let's say a 1000ms (a second). Now this works as you'd expect: <body onLoad="PopUp.style.visibility='hidden';">
2
by: JS | last post by:
Hi all, Im having some troubles with layers on a site im developing. I have two layers one has an image of an artists palette on it and each blob of paint is a link to a page on the site. That...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.