I needed this function recently, and might need it again in the future. I'm posting it here so it will be easily findable when I do need it again. FWIW, the Prototype Javascript Library handles this really well with its $ function, but the page I'm putting together doesn't need that kind of overhead.
function elementById(x) {
if (document.getElementById) return document.getElementById(x);
else if (document.all) return document.all[x];
else if (document.layers) return document.layers[x];
else return null;
}

Leave a comment