function $(id){return document.getElementById(id);
The above is no problem for new versions of browsers. If you use an old browser, you can use the following function
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;
}
}
to achieve the effect of $ replacing document.getElementById, although it is simple , but for those that do not reference frameworks such as prototype and jquery, there is no need to write document.getElementById every time, and it can be used everywhere after being defined in a public JavaScript file.