THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Area href Property

Area Object Reference 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

Internet Explorer Firefox Opera Google Chrome Safari

The href property is supported in all major browsers.


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.w3schools.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 Reference Area Object