Javascript DOM HTML Anchor port Property set

Introduction

Change the port number of a link:

document.getElementById("myAnchor").port = "80";

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" target="_blank" href="http://www.java2s.com:1234">Example link</a></p>

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

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

<script>
function myFunction() {/* w ww .  j a v  a 2s. com*/
  document.getElementById("myAnchor").port = "80";
  document.getElementById("demo").innerHTML = "The port number was changed to '80'.";
}
</script>

</body>
</html>



PreviousNext

Related