Solved

Javascript: Difference between getElementById and document.forms

Posted on 2008-10-27
3
597 Views
Last Modified: 2013-11-11
What is the difference between document.getElementById() and document.forms[0].element
0
Comment
Question by:karakav
3 Comments
 
LVL 6

Accepted Solution

by:
slinkygn earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now