Skip to content

useDomNodeTextContent

biome.json
{
"linter": {
"rules": {
"nursery": {
"useDomNodeTextContent": "error"
}
}
}
}

Prefer .textContent over .innerText for DOM node text.

Because innerText depends on rendered layout and CSS, it should only be used when you specifically need that behavior. textContent is usually faster and more predictable than innerText.

const text = node.innerText;
code-block.js:1:19 lint/nursery/useDomNodeTextContent  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

innerText is not recommended for reading DOM node text.

> 1 │ const text = node.innerText;
^^^^^^^^^
2 │

innerText depends on rendered layout and CSS, so it can be slower and produce different results from the DOM tree’s text content.

Use textContent when you want the node’s text without rendered-text behavior.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use textContent instead.

1 - const·text·=·node.innerText;
1+ const·text·=·node.textContent;
2 2

const {innerText} = node;
code-block.js:1:8 lint/nursery/useDomNodeTextContent  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

innerText is not recommended for reading DOM node text.

> 1 │ const {innerText} = node;
^^^^^^^^^
2 │

innerText depends on rendered layout and CSS, so it can be slower and produce different results from the DOM tree’s text content.

Use textContent when you want the node’s text without rendered-text behavior.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use textContent instead.

1 │ const·{textContent:·innerText}·=·node;
+++++++++++++
node["innerText"] = "Biome";
code-block.js:1:6 lint/nursery/useDomNodeTextContent  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

innerText is not recommended for reading DOM node text.

> 1 │ node[“innerText”] = “Biome”;
^^^^^^^^^^^
2 │

innerText depends on rendered layout and CSS, so it can be slower and produce different results from the DOM tree’s text content.

Use textContent when you want the node’s text without rendered-text behavior.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Use textContent instead.

1 - node[innerText]·=·Biome;
1+ node[textContent]·=·Biome;
2 2

const text = node.textContent;
const {textContent} = node;