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

Property
hostname Yes Yes Yes Yes Yes

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