Anchor text Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

The text property sets or gets the text content of a link.

Set the text property with the following Values

ValueDescription
sometext Sets the text content of a link

Return Value

A String, representing the text content of the link

The following code shows how to Return the text content of a link:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials