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.

text

Summary

Legacy. Use document.title instead. When setting, does same as textContent. When getting, gets a concatenated version of all of the child text nodes of a title element.

Property of dom/HTMLTitleElementdom/HTMLTitleElement

Syntax

var titleText = titleElement.text;
titleElement.text = newTitleText;

Return Value

Returns an object of type StringString

A concatenation of all of the child text nodes of the element.

Examples

The following script gets the text of the title element, changes “r” to “t” and sets the text back.

// Note - this example assumes that this script runs
// after the title element is created.

// Caching the first title element in the document for further use.
var title = document.getElementsByTagName("title")[0];
// Getting the text of the element, replacing the first "r"
// with "t" and setting the result back to the text property.
// Alternatively,
// use document.title = document.title.replace("r", "t"); instead.
title.text = title.text.replace("r", "t");

Usage

 Legacy. Use document.title instead.

Use this property to get a concatenated version of all of the child text nodes of a title element. Setting this property works the same way as setting the textContent property.

Notes

  • Text nodes that are nested within elements or HTML comments are excluded.

Related specifications

Document Object Model (DOM) Level 1
W3C Recommendation
Document Object Model (DOM) Level 2 HTML
W3C Recommendation
WHATWG HTML
Living Standard
HTML5
W3C Last Call Working Draft