HTML DOM Document anchors property

Definition and Usage

Not recommended anchors property. Please do not use it.

anchors The property only returns those <a> elements with the name attribute.

HTML5 does not support the name attribute of <a> elements.

Alternative:

Number of <a> elements in the document:

let num = document.getElementsByTagName("a").length;

Try it yourself

Content of the first <a> element:

let content = document.getElementsByTagName("a")[0].innerHTML;

Try it yourself

See also:

Anchor Object

Document Links Collection

Instance

Example 1

Number of <a> elements in the document:

let num = document.anchors.length;

Try it yourself

Example 2

Content of the first <a> element:

let content = document.anchors[0].innerHTML;

Try it yourself

Syntax

document.anchors

Parameter

None.

Return Value

Type Description
Object An HTMLCollection of all <a> elements in the document that have a name attribute.