Geekpedia Programming Tutorials









Crossbrowser getElementById() function

If you use this function instead of getElementById() you'll ensure your JavaScript call for this method will work with older versions of Internet Explorer as well, that don't support getElementById().

On Wednesday, March 19th 2008 at 12:10 AM
By Andrei Pociu (View Profile)
-----   (Rated 0 with 0 votes)
Contextual Ads
More JavaScript Resources
Advertisement
  1. function getElementById2(elemID)
  2. {
  3.     if(document.all) // If it's an older version
  4.     {
  5.          return eval("document.all['" + elemID + "']");
  6.  
  7.     }
  8.     else
  9.     {
  10.          return document.getElementById(elemID);
  11.     }
  12. }
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
by Mike on Sunday, March 30th 2008 at 10:40 PM

To hell with older versions of Internet Explorer! getElementById() or die!


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs JavaScript Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Downloads

Latest Icons