Area href attribute

Definition and usage

href Attribute sets or returns the area href attribute values.

href Attribute specifies the destination of the link within the area.

See also:

HTML Reference Manual:HTML <area> href attribute

Example

Example 1

Change the URL of the linked area within:

document.getElementById("venus").href = "sun.htm";

Try it yourself

Example 2

Get the URL of the linked area within:

var x = document.getElementById("venus").href;

Try it yourself

Example 3

Change the URL of the linked area to an absolute URL:

document.getElementById("venus").href = "http://www.codew3c.com/";

Try it yourself

Syntax

Return the href attribute:

areaObject.href

Set the href attribute:

areaObject.href = URL

Attribute value

Value Description
URL

Hyperlink target within the specified area.

Possible values:

  • Absolute URL - points to another website (for example href="http://www.example.com/sun.htm").
  • Relative URL - points to a file within the website (such as href="sun.htm").
  • Link to an element with a specified id within a page (such as href="#top").
  • Other protocols (such as https://, ftp://, mailto:, file: and so on.)
  • Script (such as href="javascript:alert('Hello');"))

Technical Details

Return Value: A string value representing the URL of the link. Returns the entire URL, including the protocol (such as http://).

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support