Page 1 of 1

IE & NETSCAPE document.

Posted: Wed Feb 05, 2003 6:20 pm
by Gen-ik
I've crawled through loads of JS code trying to find a simple answer to this but I haven't found a clear answer yet and was hoping someone here could help.

Do IE and NS both use the document statement in the same way?

If I had an object in the HTML page called BOB for example, could I target it using document.BOB in both browsers or do they work in different ways.

The reason I'm confused is simply because so many people use different ways of using JS.. some use if(layers).. some use if(document.all) etc.

All I'm after is a cross-browser bit of code that can target an object in the page.

Posted: Fri Feb 07, 2003 7:02 am
by DaZZleD
they use it the same way. the difference is that layer object is supported only in NS and document.all only in IE. they are both browser specific object collection and they are often use to see what type of browser the client uses.

Posted: Fri Feb 14, 2003 2:19 am
by Skyzyx
Internet Explorer 4-6 uses document.all
Netscape 4 uses document.layers

Internet Explorer 5+ and Netscape 6+ uses the (correct) document object model from the W3C. You can test for it using a DOM-specific object, like document.getElementById.

For your own sake, stay away from document.all and document.layers. They're bad news. Here's an example of proper usage.

Code: Select all

<!-- HTML Code -->
<span id="bobbo">This is a SPAN element</span>

// This is proper W3C DOM code
document.getElementById("bobbo").backgroundColor="#FFFFCC";
This is the cross-browser way of referring to HTML elements. You can always check out http://www.w3.org for the technical specs, or CodingForums.com is great for JavaScript stuff.

Hope this helps!

Posted: Fri Feb 14, 2003 4:03 am
by Gen-ik
Thanks. I discovered getElementById a while ago and it works great (obviously). It will limit the number of people who can view the website but I guess they will just have to upgrade their browsers.

Cheers.