Get Element By ID cross-browser

| | Comments (0) | TrackBacks (0)
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;
}

0 TrackBacks

Listed below are links to blogs that reference this entry: Get Element By ID cross-browser.

TrackBack URL for this entry: http://www.kpao.org/blog/cgi-bin/mt/mt-tb.cgi/353

Leave a comment