Javascript DOM HTML Anchor text Property set

Introduction

Change the text content of a link:

document.getElementById("myAnchor").text = "new text";

Click the button to change the text content 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>

<script>
function myFunction() {/*from w w w. j  av a  2 s. c  o  m*/
  document.getElementById("myAnchor").text = "new value!";
}
</script>

</body>
</html>



PreviousNext

Related