anchors collection
In Internet Explorer, the anchors collection also contains anchor elements that have an id attribute specified.
The elements in the collection are sorted in source code order.
If you need a collection of all anchor elements that have a href property specified, use the links collection.Syntax:
Properties that reference the object:
| document.anchors |
The base interface, through which you can add new functionalities to the anchors collection, is the HTMLCollection interface.
Possible members:
Properties:
Returns an integer that specifies the number of elements in the current collection.
This property is read-only. |
Methods:
[nameOrIndex] |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
|
||||||||||||||||||||||
item (nameOrIndex [, subIndex]) |
Returns an element or a collection of elements from the current collection by name or index.
Parameters:
Return value:
|
||||||||||||||||||||||
namedItem (name) |
Returns an element or a collection of elements from the current collection by name.
Parameters:
Return value:
|
||||||||||||||||||||||
tags | Returns a NodeList collection that contains all elements from the current collection with the specified tag name. | ||||||||||||||||||||||
urns | Returns a NodeList collection that contains all elements to which the specified behavior is attached. |
Example HTML code 1:
This example illustrates the use of the anchors collection:
|
||||
<head> <script type="text/javascript"> function GetAnchors () { var message = ""; for (i = 0; i < document.anchors.length; i++) { message += i + ". anchor: " + document.anchors.item (i).innerHTML + "\n"; } alert (message); } </script> </head> <body> <a name="an1" href="#">apple</a><br/> <a name="an2" href="#">peach</a><br/> <a name="an3" href="#">pear</a><br/> <br /><br /> <button onclick="GetAnchors ();">Get anchors!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
External links:
User Contributed Comments