The $ dollar sign is also used in JavaScript to replace Document.getelementbyid_ basics

Source: Internet
Author: User
Copy Code code as follows:

function $ (ID) {return document.getElementById (ID);

The above is not a problem for the new version of the browser, if you use the old browser, you can use the following function
Copy Code code as follows:

function $ (objectId) {
if (document.getElementById && document.getElementById (objectId)) {
The Consortium 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;
}
}

To implement the $ Instead of document.getElementById, the effect is simple, but for frameworks that do not reference prototype and jquery, each write document.getElementById is avoided, and can be used everywhere after a common JavaScript file is defined Out.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.