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.
IE & NETSCAPE document.
Moderator: General Moderators
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.
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!
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";Hope this helps!