I know that getElementById can be used in IE, but I don’t know if it can be used in other browsers, such as: Firebox, Opera, Netscape
Answer:
getElementById is a standard method
Theoretically Anyone who supports the w3c standard can use it. The three newer versions you listed can all be used
, but antique browsers still don’t support it, so it’s best to use the method used on this site to achieve it
function $(objectId) {
if(document.getElementById && document. getElementById(objectId)) {
// W3C DOM
return document.getElementById(objectId);
}
else if (document.all && document.all(objectId)) {
/ / MSIE 4 DOM
return document.all(objectId);
} }
else if (document.layers && document.layers[objectId]) {
// NN 4 DOM.. note: this won't find nested layers
return document.layers[objectId];
}
else {
return false;
}
}