Javascript DOM HTML Anchor protocol Property set

Introduction

Change the protocol of a link:

document.getElementById("myAnchor").protocol = "mailto:";

Click the button to change the protocol part of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

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

<script>
function myFunction() {//from w w w. j av  a  2s .com
  document.getElementById("myAnchor").protocol = "mailto:";
  document.getElementById("demo").innerHTML = "The protocol was changed.";
}
</script>

</body>
</html>



PreviousNext

Related