Javascript DOM HTML Anchor host Property set

Introduction

Change the hostname and port number of a link:

document.getElementById("myAnchor").host = "www.example.com:1111";

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

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  ww w.j av  a2s.  co  m
  document.getElementById("myAnchor").host = "www.java2s.com:80";
  document.getElementById("demo").innerHTML = "The hostname and port number changed.";
}
</script>
</body>
</html>



PreviousNext

Related