The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hide All Div Layers (quickly!)

Hey folks.

Is there a quick (in terms of performance/speed) way to hide all visible layers on a page?

Basically, I have 250+ div layers written out on a page. I use a select menu to control which layer is shown... but - and here's where it gets good - my javascript, in order to show a particular layer, has to hide every other layer, then show the particular layer. I think because there's so many layers, it's really really (really!) slow.

The code I have to hide all layers seems really dumb - but I don't have anything else. Here's my code:

yeah, don't do it that way. first of all, using the document.all() method is a performance hog, not as quick as spelling out the whole dom path because i think he looks at every one, each time until he finds the one that matches.

what you need is a to loop through a results array that you can get with:

document.getElementsByTagName("div");

i think the code would look something like this...don't hold me to this, I'm pulling this out of the air

Thanks for the code. I need to modify it because every layer is technically named differently - i.e. "layer1", "layer2", etc. I'm passing the numeric value from a list menu (which is calling the show/hide layer function).