The text
property sets or gets the text content of a link.
Return the text content of a link:
var x = document.getElementById("myAnchor").text;
Click the button to display the text content of the link.
<!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() {/*ww w . java 2 s . c om*/ var x = document.getElementById("myAnchor").text; document.getElementById("demo").innerHTML = x; } </script> </body> </html>