Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DIV - Layers

Status
Not open for further replies.

TidyTrax

Programmer
Jul 11, 2001
263
AU
How do i find out the number of layers i have in a document. Because i want to be able at one point to hide all layers and show all layers, rather than doing it by naming each one, a simple loop would suffice if i knew the number of layers i had and without cheating and counting them manually

Matt
 
document.layers is an array containing all layers for document, so document.layers.lenght is the number of layers for document ------
please review FAQ183-874 - this will help you to get the best out of tt
[ "you" is not someone in particular - don't take it too personnal ]
 
hie
iza, ur example is for netscrap, for ie i think it must be smth with document.tags array, (i've heard that there is one, but i cant get access 2 it now - what'daf.. >:-<) regards, vic
 
well, using layers in ie is weird (i haven't even tried ! i don't know if they are suported ... shame on me) - that's why i gave an ns answer ! ------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
Well i have been using the .length to get the number of layers but i cant get the dam thing to hide all the layers, anyone got code to do that, im just trying to use a for loop to hide all layers.

Matt
 
iza, i ment divs (they're still layers for me :))
TidyTrax, here u r:
for (var ii=0; ii<document.layers.length; ii++){
document.layers[ii].visibility=&quot;hide&quot;
}

2 show - use &quot;show&quot;.. its simple.. regards, vic
 
Well thats what i thought as well, but the stupid code dont work! And the piece you have just given is identical to what i had, well i'll re-try it anyway. Thanks

Matt
 
yeah, so i'll tell my babelfish that layers(nn)=div(ie) when vituz's speaking ;]]] - should have thought of this by myself anyway !!
matt, if you want to hide them all, wouldn't it be better just to replace the top with a &quot;normal&quot; (ie : without layer/div) page ? just like document.top.location=&quot;a page without layers.html&quot; ?? ------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
The layers need to appear at different times and at different points on an image, but at certain points - like at the start all layers need to be invisible. I realise taht i can make them all invisible by a rather dirty function refering to all layers by name, but thats cheating. Anyway, back to it, cheers for th help

Matt
 
hey, Tidy, may be they're nested? (i mean layers) & tell me again, r u writin for netscape or ie??? regards, vic
 
Im using IE but i am writing my code so that it is compatable with both Netscape and IE. What i have is a main image on the screen and series of layers, which pop up at specific click points on the image with relevant information, links, etc. They start of hidden, at the moment i am doing that the dirty way, by using a function and using each layers name, but i would rather my code was tidy and used a for loop to hide all.

Another quick question is that i wanted to put in a piece of code to trap the left mouse button when clicked off the certain point where it reveals a layer it will then close the active layer. The trouble is when i do that the resulting layers which pop up now no longer function, ie: the links dont work when you click on them. I realise this is because im trapping the left mouse event then passing the function to hide all layers, but how do you then do it without affecting the functionality of the newly visible layer?

Matt

ps: Hope you follow all that
 
i don't know if the answer is in it, but you should read the faq on event handling (javascript forum) - it deals with things like trapping the mouse event and releasing it ------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
u c,
for (var ii=0; ii<document.layers.length; ii++){
document.layers[ii].visibility=&quot;hide&quot;
}
is nc only syntax, u might create an array with all ur layers names & hide'em in a loop usin this array (but i bet u're doin so sayin by using a function and using each layers name)

& now about ur next question: if i got it clear, u wanna hide *active* layer when clickin somewhere else??
why not usin onblur handler?
regards, vic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top