Javascript DOM HTML Anchor Object set innerHTML Property

Introduction

Change the HTML content, URL, and target of a link:

View in separate window

<!DOCTYPE html>
<html>
<body>

<a id="myAnchor" href="http://www.microsoft.com">Microsoft</a>
<button onclick="myFunction()">Change link</button>

<script>
function myFunction() {/*from   w w w.j  a  va2 s  . com*/
  document.getElementById("myAnchor").innerHTML = "Examples";
  document.getElementById("myAnchor").href = "https://www.java2s.com";
  document.getElementById("myAnchor").target = "_blank";
}
</script>

</body>
</html>



PreviousNext

Related