X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook