Note : The All collection is Internet Explorer 4.0 specific. As Netscape doesn't support scripting for every HTML element, it doesn't support the All collection.
The All collection is an ordered, indexed array, containing a reference to every opening HTML element in a document. For example, consider the following document:
<P>This is a test
The all collection would be indexed from 0 to 5, with the elements being positioned:
Element Object would normally be retrieved by their index in the All collection (for example, above
document.all(3) contains a reference to the
<BODY> element), but a string value can be used, as long as that string is a valid identifier (
ID attribute value) for an element in the document.
E.g., changing the above example to:
<TITLE ID="Title1">Test Document</TITLE>
<P>This is a test
...would mean that
document.all('Title1') would be a reference to the
<TITLE> element (whose
ID is 'Title1'). This would be the same as
document.all(2). Note that it is also equivalent to using
document.all.item('Title1') (see the item method below).
Note : The All collection always includes a reference to
<BODY> elements, whether they exist in the document or not.
length property returns the number of elements in the collection. Note that the
length count starts at 1, not 0 as the all collection index does. Therefore, the
length property may return a value of 5, but to access the 3rd element, you'd need to use
item method retrieves single items, or sub-collections from the all collection. It accepts the following arguments:
index is a number, then the method returns a reference to the element object at that position in the all collections index. I.e. (using the example above)
TITLE - the value of the
tagName property. As you can see, this is effectively the long-hand version of using
index property is a string value, then the
item method returns a sub-collection, containing a reference to every element in the document that has its
NAME attribute set to the string contained in the
index argument. To retrieve certain element objects from this sub-collection, the
sub-index argument must be used. For example, assume that 5 elements in a document all have the
NAME attribute set as
radColour (these imaginary elements are radio buttons). To interrogate the 3rd of these elements, you could use:
tags method returns a collection of element objects whose
tagName property is the same as the
tag argument used for the method. This differs from the
item property in that that interrogates
NAME values if necessary.
would return a collection of all the
<EM> objects in the document.
© 1995-1998, Stephen Le Hunte
|file: /Techref/language/html/ib/Scripting_Reference/allcol.htm, 5KB, , updated: 2008/9/30 15:00, local time: 2018/4/20 02:06,
|©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://techref.massmind.org/techref/language/html/ib/Scripting_Reference/allcol.htm"> The All collection</A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to techref.massmind.org!