The usage of JS document.all __js

Source: Internet
Author: User

document.all usage

Document.all is a collection of all elements within a page. For example:
document.all (0) represents the first element within a page
Document.all can tell if the browser is IE
if (document.all)

Alert ("is ie!");
You can also call the element by setting the id attribute (ID=AAAA) to an element, and then using DOCUMENT.ALL.AAAA

Code 1:
<input name=aaa value=aaa>
<input id=bbb value=bbb>
<script language=jscript>
Alert ( by name
Alert (Document.all.bbb.value)//value by ID
Code 2:
But often name can be the same (e.g., using a checkbox to take a number of user preferences)
<input name=aaa value=a1>
<input name=aaa value=a2>
<input id=bbb value=bbb>
<script language=jscript>
Alert (DOCUMENT.ALL.AAA (0). Value)//display A1
Alert (DOCUMENT.ALL.AAA (1). Value)//Display A2
alert (document.all.bbb (0). Value)//This line of code will fail
Code 3:
Theoretically a page ID is not the same, if there are different tags have the same id will fail, just like this:
<input id=aaa value=a1>
<input id=aaa value=a2>
<script language=jscript>
Alert ( undefined instead of A1 or A2

That is to say document.all[] is an array variable of all the tags in the document.
Includes all elements in a Document object
Document.all[] This array can access all the elements in the document.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.