Anchor host Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

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

Property Values

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

Return Value

A String, representing the domain name or IP address and port number of the URL.

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.example.com">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>

<script>
function myFunction() {// w ww.  j  a  v a 2  s. co m
    var x = document.getElementById("myAnchor").host;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials