[thelist] Re: Accessing layers in Javascript

Ben Gustafson Ben_Gustafson at lionbridge.com
Wed Jan 30 11:24:00 CST 2002


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--
[ Picked text/plain from multipart/alternative ]
Mark Howells wrote:

> To loop through the layers on a page in Netscape 4, I'd use the
> document.layers array. To loop through the layers on a page
> in IE 4, I'd
> use the document.all array. Any idea what I can use in browsers that
> recognize document.getElementById, specifically NN6? document.all and
> document.layers aren't recognized in this browser.

Mark,

The code below will work in Netscape 6.x and Opera, if you want to get all
the DIVs and then do something only to a specific class (assuming your
layers are in DIV tags). This method is good if you use CLASS to group
layers, and ID to identify a specific layer:

--
var Layer = document.getElementsByTagName("DIV");
for (var i = 0; i < Layer.length; i++)
	if (Layer[i].getAttribute('class') == "your_class_name")
		// do something
--

As noted yesterday, there is a bug in Opera that prevents using
Layer[i].className == "your_class_name" .

--Ben



More information about the thelist mailing list