Anchor text Property
Example
Return the text content of a link:
var x = document.getElementById("myAnchor").text;
The result of x will be:
Example link
Try it yourself »
Definition and Usage
The text property sets or returns the text content of a link.
HTML elements often consists of both an element node and a text node, e.g., an <a> element with a text that says "Click me". Use this property if you want to get or set the "Click me" text.
Browser Support
The text property is supported in all major browsers.
However, when setting the text property it is only supported in Internet Explorer and Firefox.
Note: Internet Explorer 9 (and earlier versions) do not support the text property.
Syntax
Return the text property:
anchorObject.text
Set the text property:
anchorObject.text=sometext
Property Values
Value | Description |
---|---|
sometext | Specifies the text content of a link |
Technical Details
Return Value: | A String, representing the text content of the link |
---|
More Examples
Example
Change the text content of a link (only works in Internet Explorer 10+ and Firefox):
document.getElementById("myAnchor").text = "Click me to open example link!";
Try it yourself »
Anchor Object