Anchor host Property
Example
Return the hostname and port number of a link:
let text = document.getElementById("myAnchor").host;
Try it Yourself »
Change the hostname and port number of a link:
document.getElementById("myAnchor").host = "www.somenewexamplepage.com:344";
Try it Yourself »
Another example of how to change the hostname and port number of a link:
document.getElementById("myAnchor").host = "www.w3schools.com:80";
Try it Yourself »
Description
The host property sets or returns the hostname and port part of an href attribute.
Note
If the port number is not specified in the URL (or a default port - like 80, or 443), some browsers will not display the port number.
See Also:
Syntax
Return the host property:
anchorObject.host
Set the host property:
anchorObject.host = hostname:port
Parameters
Parameter | Description |
hostname:port | Specifies the hostname and port number of a URL |
Return Value
Type | Description |
String | The domain name (or IP address) and port number of a URL. |
Browser Support
host
is an HTML4 feature.
It has been supported in all browsers since 1997.
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
❮ Anchor Object