Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  DHTML, HTML & CSS

all Collection


Returns a reference to the collection of elements contained by the object.

Syntax

[ collAll = ] object.all

[ oObject = ] object.all(vIndex [, iSubIndex])

Possible Values

collAll Reference to an array of elements contained by the object.
oObject Reference to an individual item in the array of elements contained by the object.
vIndex Number or string specifying the element or collection to retrieve. If this parameter is a number, the method returns the element in the collection at the given position, where the first element has value 0, the second has 1, and so on. If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements.
iSubIndex Optional. Position of an element to retrieve. This parameter is used when vIndex is a string. The method uses the string to construct a collection of all elements that have a name or id equal to the string and then retrieves from this collection the element at the position specified by iSubIndex.

Members

Remarks

The all collection includes one element object for each valid HTML tag. If a valid tag has a matching end tag, both tags are represented by the same element object.

The collection returned by the document's all property always includes a reference to the HTML, HEAD, TITLE, and BODY objects regardless of whether the tags are present in the document.

If the document contains invalid or unknown tags, the collection includes one element object for each. Unlike valid end tags, unknown end tags are represented by their own element objects. The order of the element objects is the HTML source order. Although the collection indicates the order of tags, it does not indicate hierarchy.

Examples

The following JScript™ (compatible with ECMA 262 language specification) example displays the names of all tags in the document in the order the tags appear in the document.

for ( i = 0; i < document.all.length; i++ )
{
    alert(document.all(i).tagName);
}

The following JScript example uses the item method on the all collection to retrieve all element objects for which the name or ID attribute is set to "sample". Depending on how many times the name or ID is defined in the document, the item method may return null, a single element object, or a collection of element objects. The example uses the length property of the collection to determine whether item returned a collection or a single object.

var oObject = document.all.item("sample");
if ( oObject != null )
{
    if ( oObject.length != null )
    {
        for ( i = 0; i < oObject.length; i++ )
    {
            alert(oObject(i).tagName);
            }
        }
else 
    alert(oObject.tagName);
} 

Applies To


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site