HTML DOM Anchor Object

Anchor Object

The Anchor object represents the HTML <a> element.

Accessing Anchor Object

You can use getElementById() to access the <a> element:

var x = document.getElementById("myAnchor");

Try it yourself

Create Anchor Object

You can create an <a> element using the document.createElement() method:

var x = document.createElement("A");

Try it yourself

Anchor Object Properties

Attributes Description
charset

Not supported in HTML5.

Set or return the value of the link's charset attribute.

download Set or return the value of the link's download attribute.
hash Set or return the anchor part of the href attribute value.
host Set or return the hostname and port parts of the href attribute value.
hostname Set or return the hostname part of the href attribute value.
href Set or return the value of the link's href attribute.
hreflang Set or return the value of the link's hreflang attribute.
origin Return the protocol, hostname, and port parts of the href attribute value.
name

Not supported in HTML5.Please use element.id.

Set or return the value of the link's name attribute.

password Set or return the password part of the href attribute value.
pathname Set or return the pathname part of the href attribute value.
port Set or return the port part of the href attribute value.
protocol Set or return the protocol part of the href attribute value.
rel Set or return the value of the link's rel attribute.
rev

Not supported in HTML5.

Set or return the value of the link's rev attribute.

search Set or return the query string part of the href attribute value.
target Set or return the value of the link's target attribute.
text Set or return the text content of the link.
type Set or return the value of the link type attribute.
username Set or return the username part of the href attribute value.

Standard attributes and events

The Anchor object supports both standardAttributesandEvents.

Related pages

HTML Tutorial:HTML Link

HTML Reference Manual:HTML <a> Tag