Can any one explain what is the difference between
document.all
and the
document.forms[0]
please?
Thank you
document.all
gives you a reference to an array-like object containing all elements of the document in Internet Explorer (IE). Document.forms[0]
gives you a pointer to the first form element in the document, in all browsers
The 2 are quite different then. If your form had a name attribute, say 'myform', then in IE that form could be referenced with document.all.myform
document.all
is deprecated from IE version 5 and up. You can still use it though, even in IE9 it's still available. Often it's used to test if the browser is IE:
if (document.all) {
//o no, it's IE again! We have to do it another way!
}
Referencing forms in the form of document.forms[0]
is considered bad practice. More on that can be found here
NOTE: Since this answer was first written IE11 has been introduced which dropped support for document.all See Compatibility changes in IE11 for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With