View Full Version : Browser support for selecting elements

Mar 23rd, 2007, 07:27 PM
Hey all,

I've got a script to toggle a DIV on and off.. but I'm not entirely sure it'll work in as many browsers as possible. Can anyone tell me if what I have is sufficient, or if there are any ways to increase its support to work properly?

This is my code:

if (document.layers) var e = document.layers[''+id+'']
else if (document.all) var e = document.all[''+id+'']
else if (document.getElementById) var e = document.getElementById(''+id+'')

Many thanks!

Philip M
Mar 23rd, 2007, 07:36 PM
Should work in Netscape 4+, IE5+ and all modern browsers.

Mar 23rd, 2007, 07:51 PM
Also in IE4.

document.layers is for Netscape 4
document.all is for IE4
document.getElementById is for all modern browsers including IE5+, Opera 5+, Netscape 6+, Firefox, Safari, etc.

Dropping the first two lines will have little effect as few people are using Netscape 4 or IE4 any longer.

Mar 23rd, 2007, 09:40 PM
Oh, well that's good to know. I didn't realise getElementById covered so many. Cheers guys!