links Collection

Retrieves a collection of all a objects that specify the href property and all area objects in the document.

Syntax

[ oColl = ] object.links
[ oObject = ] object.links(iIndex)

Possible Values

oColl Array of a objects.
oObjectReference to an individual item in the array of elements contained by the object.
iIndexRequired. Integer that specifies the zero-based index of the item to be returned.

Members Table

The following table lists the members exposed by the links object.

Attributes/Properties
PropertyDescription
length Sets or retrieves the number of objects in a collection.
Methods
MethodDescription
item Retrieves an object from various collections, including the all collection.
namedItem Retrieves an object or a collection from a specified collection.
tags Retrieves a collection of objects that have the specified HTML tag name.
urns Retrieves a collection of all objects to which a specified behavior is attached.

Remarks

For a objects to appear in the collection, they must have an href attribute.

Example

This example shows how to display the href of the third link (Microsoft.com) defined in the document.

<a href="http://yahoo.com">Yahoo.com</a>
<a href="http://msn.com">MSN.com</a>
<a href="http://microsoft.com">Microsoft.com</a>

<script>
alert(document.links[2].href);
</script> 

Standards Information

This collection is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 World Wide Web link.

Applies To

document, HTMLDocument Constructor
Tags :


Page view tracker