1. Web
  2. Web APIs
  3. Text
  4. Text()

Text: Text() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨October 2017⁩.

The Text() constructor returns a new Text object with the optional string given in parameter as its textual content.

Syntax

js
new Text()
new Text(string)

Parameters

string Optional

A string representing the textual content of the text node.

Return value

A new Text object with the content of the string parameter, or the empty string if no parameter was given.

Example

js
let text = new Text("Test");

Specifications

Specification
DOM
# ref-for-dom-text-text1

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /