View Single Post
Old May 24th, 2006, 3:42 PM   #8
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Nono, setAttribute is standard JavaScript. IE doesn't like standards, heh.
As for your original get_object function - if / else ifs in interpreted languages are costly and setting a flag for the right kind of element getting function is definitely not the right way to go about it. How about something like this:
var getObject = function() {};
if (document.getElementById) {
    getObject = document.getElementById;
}
else if (document.all) {
    getObject = function(s) { return document.all[s]) };
}
var foo = getObject("foo");
etc..
Another note is to make sure you're not making inferences about functionality supported by the browser just by checking to see if it supports document.all or document.layers or some such. It makes no sense to do so and is akin to browser detection. You should always check for the object you want to use, not a browser that you know supports it; else your scripts will be severely crippled in a bunch of browsers.
Cerulean is offline   Reply With Quote