You Are Here Home > document.getElementById On All Browsers – Cross...

document.getElementById On All Browsers – Cross browser getElementById

Here is a little JavaScript function that gets an object according to it’s id and it’s cross browser.

/*********************************************************************
   * Get an object, this function is cross browser
   * Usage:
   * var object = get_object(element_id);
   * @Author Hamid Alipour http://blog.code-head.com/
  **/
  function get_object(id) {
   var object = null;
   if (document.layers) {
    object = document.layers[id];
   } else if (document.all) {
    object = document.all[id];
   } else if (document.getElementById) {
    object = document.getElementById(id);
   }
   return object;
  }
  /*********************************************************************/
document.getElementById On All Browsers – Cross browser getElementById
Filed under: JavaScript, Web Browsers, Web Development   Posted by: Codehead

Got a Question?

Get answers here.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment