The text
property sets or gets the text content of a link.
text |
Yes | Yes | Yes | Yes | Yes |
Return the text property:
var v = anchorObject.text
Set the text property:
anchorObject.text = sometext;
Value | Description |
---|---|
sometext | Set the link text |
A String representing the text content of the link.
The following code shows how to get the text content of a link.
<!DOCTYPE html>
<html>
<body>
<!--from ww w. j a v a 2 s . com-->
<p><a id="myAnchor" href="http://www.example.com/test.htm#part2">Example link</a></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myAnchor").text;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the text content of a link.
<!DOCTYPE html>
<html>
<body>
<!--from w ww. ja va 2s. c o m-->
<p><a id="myAnchor" href="http://www.example.com/test.htm#part2">Example link</a></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myAnchor").text = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows: