09
Mar
10

document.all() -  is a non-standard way of accessing DOM elements. It was introduced in Internet Explorer 4, because the W3C DOM hadn’t yet standardised a way of grabbing references to elements using their ID. By the time IE 5 came out, document.getElementById() had been standardised and as a result, IE 5 included support for it.
document.getElementById() -  is a standard and fully supported. Each element have a unique id on the document. It is supported by every Javascript supporting browser released since 1998.

Or you can use:

JavaScript

if(document.getElementById){  //DOM
  element = document.getElementById(id);
}
else if (document.all) {  //IE
  element = document.all[id];
}
else if (document.layers){  //Netscape < 6
  element = document.layers[id];
}
  • del.icio.us
  • Digg
  • Facebook
  • LinkedIn
  • Google Bookmarks
  • Twitter
  • MySpace
  • Mixx
  • Reddit
  • DZone
  • Sphinn
  • StumbleUpon
  • Blogplay
  • Diigo
  • Live
  • MSN Reporter
  • Technorati
  • NewsVine
  • Yahoo! Bookmarks
  • Netvibes
  • Design Float
  • Add to favorites
  • email
  • Yahoo! Buzz
  • Gwar
  • FriendFeed
  • Tumblr
  • Print
  • PDF
  • RSS

About Midhun Devasia

I am working as a Technical Manager for a Web Development company at Cochin, India. Completed my B.Tech Computer Science and Engineering from SNGCE. I'm the lead developer of Tutorboy.com.
This entry was posted in Javascript and tagged , , . Bookmark the permalink.

2 Responses to document.all vs document.getElementById

  1. Sreejith Sreedharan says:

    why use document.getElementById ?????

    you can use $(“someid”) as in jquery and mootools

    • Midhun Devasia says:

      @Sreejith Sreedharan: You can use $() function instead of this, if you are using any Js framework in your web-application.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>