Click to See Complete Forum and Search --> : Hide layers


zebdaag
11-23-2003, 10:20 AM
Hi,

I've written a script in which al lot of layers pop up. In the begin they are hidden and after a few seconds they pop up (show) this is all working great. Now I want a script that got the layer back to hidden again but.

The layers have names (codes) like:
ABD01
DBC02
EDB03
EFG02
AED02
Etc..

I wanna make buttons that can say close all layer with an A in there name...... is this possible and how can I do this!?!

Greatzz

Khalid Ali
11-23-2003, 01:55 PM
put the following function in any onclick event

function HideAll(){
var els = document.getElementsByTagName("div");
//I have assumed you have elements of name div, you can change it to any type you want
//esuch as "input", "form", "span" etc.
var len = els.length;
for(var n=0;n<len;n++){
var obj = els[n];
if(obj!=null){
obj.style.visibility="hidden";
}
}
}

zebdaag
11-24-2003, 02:17 AM
okay but what part makes sure that only the popup with an A in there name close??

zebdaag
11-25-2003, 03:57 AM
Okay i tried the script and it doesn't work right. It closes all "div" layers. But the thing I wanted was that only the layer with an A somwheren in it's div ID close on a click.

For example.

Layers with the name (div id):

AB01
BA03
CDB01
DEC01
ADE04

Are opend (shown) and i want that on a click of a button the layer with an A in there name go away (hide). So that will be the layers AB01, BA03, ADE04 will hide.!!

ray326
11-25-2003, 11:48 AM
Here's a MINOR mod to Khalid's function that does what you need.

function HideAll(pat){
var els = document.getElementsByTagName("div");
var len = els.length;
for(var n=0;n<len;n++){
var obj = els[n];
if(obj!=null && obj.id.match(pat)){
obj.style.visibility="hidden";
}
}
}

Call it with an onclick="HideAll('A')" for example.

Oh, and here's a variant that "collapses" the hidden divs and unhides the divs with IDs that don't match the pattern:


function HideAll(pat){
var els = document.getElementsByTagName("div");
var len = els.length;
for(var n=0;n<len;n++){
var obj = els[n];
if(obj!=null && obj.id.match(pat)){
obj.style.display="none";
}
else { obj.style.display="block"; }
}
}

zebdaag
11-25-2003, 05:23 PM
it works great but I made a mistake in my thinking and I didn't needed it for hiding but for showing. So the first script works great but it doesn't need to hide all layers with an A in there ID but it has to hide all but the ones with in A in there ID...
Sorry for my mistake

ray326
11-25-2003, 10:37 PM
So you use !obj.id.match(pat) in the test.

zebdaag
11-27-2003, 11:27 AM
i tried that this is what is happening...!? watch the files I added. test.html is the file wich works test2.html is the file that is edited and doesn't work.

greetz Joost

zebdaag
11-30-2003, 03:33 PM
can someone help me with this? test.htm works. it removes all layer with ID A
test 2 doesn't work it has to remove all but the layer with ID A... can someone help mee.
By the way it does remove all but the ID A but it also removes everything what is in the layer..!

ray326
11-30-2003, 07:41 PM
Originally posted by zebdaag
can someone help me with this? test.htm works. it removes all layer with ID A
test 2 doesn't work it has to remove all but the layer with ID A... can someone help mee.
By the way it does remove all but the ID A but it also removes everything what is in the layer..!
If you'd throw out all the cutesy crap and build a page that actually helped you test the functionality you'd be in a lot better shape. The function is now misnamed but it is essentially working correctly. A decent test page would help you sort out the other problems with your concept.

zebdaag
12-01-2003, 06:12 AM
thnx the back to basic tip worked!!