Javascript DOM HTML Anchor port Property get

Introduction

The port property sets or gets the port of the href attribute value.

Return the port number of a link:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>
<p><a id="myAnchor" href="http://www.java2s.com:80">Example link</a></p>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*  ww w  . ja va  2s.co m*/
  var x = document.getElementById("myAnchor").port;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related