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

HTML DOM anchors collection

HTML DOM anchors collection

Document Object Reference Document Object


Definition and Usage

The anchors collection returns an array of all hyperlinks on the current page.

Syntax

document.anchors[].

property


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the anchors collection


Example

Example 1

Returns the number of links in the document:

Runoob Tutorial(runoob.com)

HTML Tutorial

CSS Tutorial

XML Tutorial

JavaScript Tutorial

Number of anchors:

The example above produces the following output:

Number of anchors: 3

Try it »

Example 2

Returns the anchor text of the first hyperlink in the document:

Runoob Tutorial(runoob.com)

HTML Tutorial

CSS Tutorial

XML Tutorial

First anchor in the document:

The example above produces the following output:

First anchor in the document: HTML Tutorial

Try it »


Document Object Reference Document Object