The difference between document.all and document.forms [0]

Can anyone explain what is the difference between

document.all 

and document.forms[0] please?

thanks

+4
source share
3 answers

document.all provides a reference to an object that looks like an array containing all the elements of a document in Internet Explorer (IE). Document.forms[0] gives a pointer to the first form element in the document, in all browsers

At the same time 2. If your form had a name attribute, say "myform", then in IE this form can be specified using document.all.myform

document.all deprecated from IE version 5 and above. You can still use it, although it is still available in IE9. Often it is used to check if the IE browser is:

 if (document.all) { //o no, it IE again! We have to do it another way! } 

Linking to forms in the form Document.forms[0] is considered bad practice. Learn more about this here.

NOTE. Since this answer was first written, IE11 was introduced which refused to support document.all . See Compatibility Changes in IE11 for More Information.

+5
source

The document.all property is an array of all HTML elements that are in the document. and Document.forms [0] is the first form of the document. You should avoid using document.all.

Internet Explorer 4 introduced document.all DOM (Document Object Model) to provide access to various parts of a web page. Soon after, the standard DOM method getElementById was introduced and therefore available in all browsers of version 5+. This means that document.all links are only necessary for IE4 support. It’s just that no one starts IE4 anymore and so document.all DOM support no longer exists. required.

For details on how to use document.form [0], read this .

+3
source

first you use document.all.myform to access your form. in the second format, you can use document.forms [0] to access your form

  both one two is same in function but two is better than one document.all.myform using this your searching all the way rome. 
0
source

All Articles