THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Anchor hostname Property

Anchor Object Reference Anchor Object

Example

Return the hostname of a link:

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

The result of x will be:

www.example.com
Try it yourself »

Definition and Usage

The hostname property sets or returns the hostname part of the href attribute value.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The hostname property is supported in all major browsers.


Syntax

Return the hostname property:

anchorObject.hostname

Set the hostname property:

anchorObject.hostname=hostname

Property Values

Value Description
hostname Specifies the hostname of a URL

Technical Details

Return Value: A String, representing the domain name (or IP address) of the URL

More Examples

Example

Change the hostname of a link:

document.getElementById("myAnchor").hostname = "www.somenewexamplepage.com";
Try it yourself »

Example

Another example of how to change the hostname of a link:

document.getElementById("myAnchor").hostname = "www.w3schools.com";
Try it yourself »

Related Pages

JavaScript reference: location.hostname Property


Anchor Object Reference Anchor Object