This page is Almost Ready

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



Legacy. Use anchorElement.textContent instead. Functions identically to Node.textContent.

Property of dom/HTMLAnchorElementdom/HTMLAnchorElement


var anchorText = anchorElement.text;
anchorElement.text = newAnchorText;

Return Value

Returns an object of type StringString

The text content of the element.


The following script replaces every instance of the letter “a” in the text of an a element with instances of the letter "t", using the text property for getting and setting the text.

// Caching the a element for further use.
var anchor = document.getElementById("some-anchor");
// Getting the text of the element, replacing
// any "a" with "t" using a regular expression
// and setting the result back to the text property.
// Alternatively,
// use anchor.textContent = anchor.textContent.replace(/a/g, "t"); instead.
anchor.text = anchor.text.replace(/a/g, "t");

Related specifications

Living Standard
W3C Last Call Working Draft