X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Anchor text Property

Anchor Object Reference Anchor Object

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

Internet Explorer Firefox Opera Google Chrome Safari

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 Reference Anchor Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook