Home > Web Front-end > JS Tutorial > Replies to questions about whether getElementById can be used in any browser_Basic knowledge

Replies to questions about whether getElementById can be used in any browser_Basic knowledge

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:13:38
Original
1218 people have browsed it

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

Copy code 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;
}
}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template