Anchor hostname Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


The hostname property sets or gets the hostname part of the href attribute value.

Property Values

hostname Sets the hostname of a URL

Return Value

A String, representing the domain name or IP address of the URL

The following code shows how to Return the hostname of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<p><a id="myAnchor" href="">Example link</a></p>

<p>Click the button to change the hostname of the link above.</p>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {/*from  w  w  w.j  a  v  a  2s .  c o  m*/
    var x = document.getElementById("myAnchor").host;
    document.getElementById("demo").innerHTML = x;


Related Tutorials