AnchorArray object (Object/DOM)

An array of Anchor objects retrieved from the document.anchors property.

Availability:

DOM level - 1
JavaScript - 1.0
JScript - 3.0
Internet Explorer - 4.0
Netscape - 2.0
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.

Warnings:

Example code:

   <!-- 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[]

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
length1.0 1.03.0 3.02.0 2.04.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly