Javascript DOM HTML Anchor host Property get

Introduction

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

Return the hostname and port number of a link:

Click the button to display the hostname and port number of the link.

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

View in separate window

<!DOCTYPE html>
<html>
<body>
<p><a id="myAnchor" href="http://www.example.com:1234">Example link</a></p>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>
<script>
function myFunction() {/*from www.j  av a 2 s. c  om*/
  var x = document.getElementById("myAnchor").host;
  document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>



PreviousNext

Related