Latest web development tutorials
 

Area href Property

< Area Object

Example

Change the URL of a link in an area:

document.getElementById("venus").href = "sun.htm";
Try it Yourself »

Definition and Usage

The href property sets or returns the value of the href attribute of an area.

The href attribute specifies the destination of a link in an area.


Browser Support

Property
href Yes Yes Yes Yes Yes

Syntax

Return the href property:

areaObject.href

Set the href property:

areaObject.href=URL

Property Values

Value Description
URL Specifies the hyperlink target for the area.

Possible values:
  • An absolute URL - points to another web site (like href="http://www.example.com/sun.htm")
  • A relative URL - points to a file within a web site (like href="sun.htm")
  • Link to an element with a specified id within the page (like href="#top")
  • Other protocols (like https://, ftp://, mailto:, file:, etc..)
  • A script (like href="javascript:alert('Hello');")

Technical Details

Return Value: A String, representing the URL of the link. Returns the entire URL, including the protocol (like http://)

More Examples

Example

Get the URL of a link in an area:

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

The result of x will be:

http://www.w3ii.com/jsref/venus.htm
Try it Yourself »

Example

Change the URL of a link in an area to an absolute URL:

document.getElementById("venus").href = "http://www.cnn.com/";
Try it Yourself »

Related Pages

HTML reference: HTML <area> href attribute


< Area Object