Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM links collection

HTML DOM links collection

Document Object Reference Document Object


Definition and Usage

The links collection returns an array of all links in the current document.

Tip: The links collection counts tags and tag.

Syntax

document.links[]

.property


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the links collection


Example

Example 1

Returns the number of links in the document:

Runoob Tutorial(runoob.com) Planets Sun Mercury Venus

JavaScript Tutorial

Number of links/addresses:

The example above produces the following output:

Number of links/addresses: 4

Try it »

Example 2

Returns the first link of the document:

Runoob Tutorial(runoob.com) Planets Sun Mercury Venus

JavaScript Tutorial

ID of the first link/address:

The example above produces the following output:

ID of the first link/address: sun

Try it »


Document Object Reference Document Object