It's a form of feature detection for getElementById
- pretty much:
function id(i)
{
var e;
if (document.getElementById) // the standard way
return document.getElementById(i);
else if (document.all) // old IE model, needed for very old IE versions
return document.all[i];
else if (document.layers) // old netscape model, Netscape 4 etc.
return document.layers[i];
return null;
}
Unless you're supporting IE < 5.5 or Netsape < 6 , both of which you shouldn't support in all honesty - you should avoid this form of feature detection today.
This sort of code is quite common today in order to perform feature detection. I'd like to emphasize the fact that that code was best practice when it was written but is useless today. For example, today you have things like:
if ( !window.requestAnimationFrame ) {
window.requestAnimationFrame = ( function() {
return window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback,element) {
window.setTimeout( callback, 1000 / 60 );
};
} )();
}
Performing the exact same thing, only for newer APIs.