Change the hostname of a link:
document.getElementById("myAnchor").hostname = "www.example.com";
Click the button to change the hostname of the link.
<!DOCTYPE html> <html> <body> <p><a id="myAnchor" href="http://www.example.com:80/">Example link</a></p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*w ww . j a v a 2 s . co m*/ document.getElementById("myAnchor").host = "www.java2s.com"; document.getElementById("demo").innerHTML = "The hostname changed."; } </script> </body> </html>