> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/manipulation/.text.md).

# .text()

`.text()` gets or sets plain text.

***

#### Syntax

```js
element.text();
element.text(textValue);
element.text(callback);
```

***

#### Parameters

* `textValue` → new text content
* `callback` → function that receives current text and returns new text

***

#### Output

Getter:

```js
string
```

Setter:

```js
HTMLElement | NodeList | HTMLCollection
```

***

#### Example

```js
$('#title').text('Dashboard');
```

```js
$('#counter').text(current => Number(current) + 1);
```

***

#### Use cases

Use `.text()` to:

* Display user-provided values as plain text.
* Update a count, label, or status message.
* Read text from an element for comparison or processing.

***

#### More examples

Read the text from a heading:

```js
const pageTitle = $('h1').text();
```

Show a search result count:

```js
$('#result-count').text(`${results.length} results`);
```

Display a user name without rendering HTML:

```js
$('#welcome').text(`Welcome, ${user.name}`);
```

***

#### Key Takeaway

> `.text()` is safer when you only want text.
