Availability: |
| ||||||
JavaScript syntax: | - | myAnchorArray = myDocument.anchors | |||||
Object properties: | length |
The AnchorArray object is a sub-class of the Array object but has no additional properties. It responds to the length property request as you would expect.
Any Anchor objects in this array can be accessed by index value because the Array class supports that. In Netscape, the individual Anchor objects are accessible associatively by their NAME attribute. However, MSIE does not make this associative mechanism available.
In MSIE, the AnchorArray object is a kind of Collection object and so it can be searched with the item() and tags() methods.
Netscape adds a constructor property to this object class from which you can request the name to determine the object class. Actually Netscape provides constructors for virtually everything, but MSIE only supports them when it's necessary and useful.
Be aware that renaming an anchor in MSIE will add a new item to the AnchorArray collection without destroying the old one. However, the length property remains the same. It does mean that you could have problems enumerating the collection. But then, why would you ever want to rename an anchor after it has been instantiated and named within the HTML tag?
<!-- Catalog of anchors in an array --> <HTML> <HEAD> </HEAD> <BODY> <A NAME="A1" HREF="http://www.apple.com/">Apple</A><BR> <A NAME="A2" HREF="http://www.wrox.com/">Wrox</A><BR> <A NAME="A3" HREF="http://www.msdn.com/">Microsoft</A><BR> <BR> <HR> <TABLE BORDER=1> <TH>Index</TH> <TH>Name</TH> <TH>Text</TH> <TH>URL</TH> <TH>Tab index</TH> <TH>Protocol (long)</TH> <SCRIPT> myLength = document.anchors.length; for (myEnumerator=0; myEnumerator<myLength; myEnumerator++ ) { document.write("<TR><TD>"); document.write(myEnumerator); document.write("</TD><TD>"); document.write(document.anchors[myEnumerator].name); document.write("</TD><TD>"); document.write(document.anchors[myEnumerator].innerText); document.write("</TD><TD>"); document.write(document.anchors[myEnumerator].href); document.write("</TD><TD>"); document.write(document.anchors[myEnumerator].tabIndex); document.write("</TD><TD>"); document.write(document.anchors[myEnumerator].protocolLong); document.write("</TD></TR>"); } </SCRIPT> </TABLE> </BODY> </HTML>
See also: | Anchor object, Collection object, Document.anchors[] |
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
length | 1.0 ![]() | 3.0 ![]() | 2.0 ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ReadOnly |
Prev | Home | Next |
Anchor.y | Up | AnchorArray.length |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |