HTML DOM Anchor text Property
THE WORLD'S LARGEST WEB DEVELOPER SITE

Anchor text Property

❮ Anchor Object

Example

Return the text content of a link:

var x = document.getElementById("myAnchor").text;
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

Property
text Yes 10.0 Yes Yes Yes

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