Javascript examples for DOM HTML Element:Anchor
The text property sets or gets the text content of a link.
Set the text property with the following Values
Value | Description |
---|---|
sometext | Sets the text content of a link |
A String, representing the text content of the link
The following code shows how to Return the text content of a link:
<!DOCTYPE html> <html> <body> <p><a id="myAnchor" href="http://www.example.com/test.htm#part2">Example link</a></p> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w ww . j a v a 2 s.c o m*/ var x = document.getElementById("myAnchor").text; console.log(x); } </script> </body> </html>