Anchor hostname Property
Example
Return the hostname of a link:
var x = document.getElementById("myAnchor").hostname;
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
