Latest web development tutorials
 

Anchor host Property

< Anchor Object

Example

Return the hostname and port number of a link:

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

The result of x will be:

www.example.com:4097
Try it Yourself »

Definition and Usage

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

Note: If the port number is not specified in the URL (or if it is the scheme's default port - like 80, or 443), some browsers will not display the port number.


Browser Support

Property
host Yes Yes Yes Yes Yes

Syntax

Return the host property:

anchorObject.host

Set the host property:

anchorObject.host=hostname:port

Property Values

Value Description
hostname:port Specifies the hostname and port number of a URL

Technical Details

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

More Examples

Example

Change the hostname and port number of a link:

document.getElementById("myAnchor").host = "www.somenewexamplepage.com:344";
Try it Yourself »

Example

Another example of how to change the hostname and port number of a link:

document.getElementById("myAnchor").host = "www.w3ii.com:80";
Try it Yourself »

Related Pages

JavaScript reference: location.host Property


< Anchor Object