Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript: Difference between getElementById and document.forms

Posted on 2008-10-27
3
Medium Priority
?
614 Views
Last Modified: 2013-11-11
What is the difference between document.getElementById() and document.forms[0].element
0
Comment
Question by:karakav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
slinkygn earned 2000 total points
ID: 22810886
GetElementById complies with the W3C Level 1 DOM, while the forms[] array does not -- it's Level 0 DOM.  In general, the first is recommended unless you need compatibility with very old browsers.

But beyond that, both will give you a DOM object in return, and so are functionally similar.
0
 
LVL 15

Expert Comment

by:Tomarse111
ID: 22810899
Is it not just a different way of getting the same object?

document.forms is part of the DOM specification and so should not be unnecessarily avoided in favour of getElementById, simply use whatever is easiest.
0
 
LVL 4

Author Closing Comment

by:karakav
ID: 31510225
Thanks.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question