Search code examples
javascriptgetelementbyid

document.all vs. document.getElementById


When should you use document.all vs. document.getElementById?


Solution

  • document.all is a proprietary Microsoft extension to the W3C standard.

    getElementById() is standard - use that.

    However, consider if using a js library like jQuery would come in handy. For example, $("#id") is the jQuery equivalent for getElementById(). Plus, you can use more than just CSS3 selectors.