Can getElementById be used in any browser? Q: I know that getElementById can be used in IE, but I don't know if it can be used in other browsing scenarios, such as Firebox, Opera, netscape
Answer:
GetElementById is a standard method
Theoretically, all versions that support w3c standards can be used in all the three new versions you listed.
However, the antique browser is not supported, so it is best to use the method used on this site to achieve
The Code is as follows:
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;
}
}