source: www/manuals/HTML_Reference/scripting_reference/allcol.htm@ 1

Last change on this file since 1 was 1, checked in by george, 17 years ago

Prvotní import všeho

File size: 5.7 KB
Line 
1<HTML>
2<!-- This file is part of the HTML Reference Library ('HTMLib') -->
3<!-- It should not be used outside of the HTMLib package -->
4<!-- The HTMLib is © 1995-1998 Stephen Le Hunte -->
5<!-- htmlib@htmlib.demon.co.uk -->
6<HEAD>
7<LINK REL="stylesheet" HREF="../style.css" TYPE="text/css">
8<TITLE>The All collection</TITLE>
9</HEAD>
10<BODY TOPMARGIN="0" BGCOLOR="#FFFFE0" TEXT="#000000">
11
12<CENTER>
13<SPAN CLASS="NSRtitle">The All Collection</SPAN>
14</CENTER>
15
16<P><STRONG><EM>Note : </EM></STRONG>The All collection is <STRONG>Internet Explorer</STRONG> 4.0 specific. As <STRONG>Netscape</STRONG> doesn't support scripting for <EM>every</EM> HTML element, it doesn't support the All collection.
17
18<P>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:
19
20<SPAN CLASS="egcode">
21<BLOCKQUOTE>
22<CODE>&lt;HTML&gt;<BR>
23&lt;HEAD&gt;<BR>
24&lt;TITLE&gt;Test Document&lt;/TITLE&gt;<BR>
25&lt;/HEAD&gt;<BR>
26&lt;BODY&gt;<BR>
27&lt;P&gt;This is a test<BR>
28&lt;HR&gt;<BR>
29&lt;/BODY&gt;<BR>
30&lt;/HTML&gt;
31</CODE>
32</BLOCKQUOTE>
33</SPAN>
34
35<P>The all collection would be indexed from 0 to 5, with the elements being positioned:
36
37<P>
38<TABLE WIDTH="60%">
39<COLGROUP SPAN="2" ALIGN="center">
40<TR>
41 <TD><STRONG>Element</STRONG></TD>
42 <TD><STRONG>All index</STRONG></TD>
43</TR>
44<TR>
45 <TD><CODE>&lt;HTML&gt;</CODE></TD>
46 <TD>0</TD>
47</TR>
48<TR>
49 <TD><CODE>&lt;HEAD&gt;</CODE></TD>
50 <TD>1</TD>
51</TR>
52<TR>
53 <TD><CODE>&lt;TITLE&gt;</CODE></TD>
54 <TD>2</TD>
55</TR>
56<TR>
57 <TD><CODE>&lt;BODY&gt;</CODE></TD>
58 <TD>3</TD>
59</TR>
60<TR>
61 <TD><CODE>&lt;P&gt;</CODE></TD>
62 <TD>4</TD>
63</TR>
64<TR>
65 <TD><CODE>&lt;HR&gt;</CODE></TD>
66 <TD>5</TD>
67</TR>
68</TABLE>
69
70<P>Element Object would normally be retrieved by their index in the All collection (for example, above <CODE>document.all(3)</CODE> contains a reference to the <CODE>&lt;BODY&gt;</CODE> element), but a string value can be used, as long as that string is a valid identifier (<CODE>ID</CODE> attribute value) for an element in the document.
71
72<P>E.g., changing the above example to:
73
74<SPAN CLASS="egcode">
75<BLOCKQUOTE>
76<CODE>&lt;HTML&gt;<BR>
77&lt;HEAD&gt;<BR>
78&lt;TITLE ID="Title1"&gt;Test Document&lt;/TITLE&gt;<BR>
79&lt;/HEAD&gt;<BR>
80&lt;BODY&gt;<BR>
81&lt;P&gt;This is a test<BR>
82&lt;HR&gt;<BR>
83&lt;/BODY&gt;<BR>
84&lt;/HTML&gt;
85</CODE>
86</BLOCKQUOTE>
87</SPAN>
88
89<P>...would mean that <CODE>document.all('Title1')</CODE> would be a reference to the <CODE>&lt;TITLE&gt;</CODE> element (whose <CODE>ID</CODE> is 'Title1'). This would be the same as <CODE>document.all(2)</CODE>. Note that it is also equivalent to using <CODE>document.all.item('Title1')</CODE> (see the item method below).
90
91<P><STRONG><EM>Note : </EM></STRONG>The All collection <STRONG>always</STRONG> includes a reference to <CODE>&lt;HTML&gt;</CODE>, <CODE>&lt;HEAD&gt;</CODE> and <CODE>&lt;BODY&gt;</CODE> elements, whether they exist in the document or not.
92
93<P><A NAME="properties"><STRONG>Properties</STRONG></A><BR>
94
95<P><SPAN CLASS="attr">length</SPAN><BR>
96The <CODE>length</CODE> property returns the number of elements in the collection. Note that the <CODE>length</CODE> count starts at 1, not 0 as the all collection index does. Therefore, the <CODE>length</CODE> property may return a value of 5, but to access the 3rd element, you'd need to use <CODE>document.all(2).<EM>property</EM></CODE>
97
98<P><A NAME="methods"><STRONG>Methods</STRONG></A>
99
100<P><SPAN CLASS="attr">item</SPAN><BR>
101The <CODE>item</CODE> method retrieves single items, or sub-collections from the all collection. It accepts the following arguments:
102
103<BLOCKQUOTE><EM>all</EM>.<STRONG>item</STRONG><EM>(index, sub-index)</EM>
104</BLOCKQUOTE>
105
106<P>If <CODE>index</CODE> 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)
107
108<SPAN CLASS="egcode">
109<BLOCKQUOTE>
110<CODE>strTag=document.all.item(2).tagName
111</CODE>
112</BLOCKQUOTE>
113</SPAN>
114
115<P>would make <CODE>strTag</CODE> be <CODE>TITLE</CODE> - the value of the <CODE>&lt;TITLE&gt;</CODE> elements <CODE>tagName</CODE> property. As you can see, this is effectively the long-hand version of using <CODE>document.all(2).<EM>property</EM></CODE>.
116
117<P>If the <CODE>index</CODE> property is a string value, then the <CODE>item</CODE> method returns a sub-collection, containing a reference to every element in the document that has its <CODE>ID</CODE> or <CODE>NAME</CODE> attribute set to the string contained in the <CODE>index</CODE> argument. To retrieve certain element objects from this sub-collection, the <CODE>sub-index</CODE> argument must be used. For example, assume that 5 elements in a document all have the <CODE>NAME</CODE> attribute set as <CODE>radColour</CODE> (these imaginary elements are radio buttons). To interrogate the 3rd of these elements, you could use:
118
119<SPAN CLASS="egcode">
120<BLOCKQUOTE>
121<CODE>strThird=document.all('radColour',2).<EM>propertyName</EM>
122</CODE>
123</BLOCKQUOTE>
124</SPAN>
125
126<P><A NAME="methtags"><SPAN CLASS="attr">tags</SPAN></A><BR>
127The <CODE>tags</CODE> method returns a collection of element objects whose <CODE>tagName</CODE> property is the same as the <CODE>tag</CODE> argument used for the method. This differs from the <CODE>item</CODE> property in that that interrogates <CODE>ID</CODE> and <CODE>NAME</CODE> values if necessary.
128
129<SPAN CLASS="egcode">
130<BLOCKQUOTE>
131<CODE>document.all.tags('EM')
132</CODE>
133</BLOCKQUOTE>
134</SPAN>
135
136<P>would return a collection of all the <CODE>&lt;EM&gt;</CODE> objects in the document.
137
138
139<P>
140<P ALIGN="right" CLASS="copyright">© 1995-1998, Stephen Le Hunte</P>
141</BODY>
142</HTML>
Note: See TracBrowser for help on using the repository browser.