Skip to content

Latest commit

Β 

History

History
42 lines (28 loc) Β· 1.12 KB

prefer-dom-node-text-content.md

File metadata and controls

42 lines (28 loc) Β· 1.12 KB

prefer-dom-node-text-content

πŸ“ Prefer .textContent over .innerText.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ’‘ This rule is manually fixable by editor suggestions.

Enforces the use of .textContent over .innerText for DOM nodes.

There are some advantages of using .textContent, like performance and more predictable behavior when updating it.

Note that there are differences between them.

Examples

// ❌
const text = foo.innerText;

// βœ…
const text = foo.textContent;
// ❌
const {innerText} = foo;

// βœ…
const {textContent} = foo;
// ❌
foo.innerText = 'πŸ¦„';

// βœ…
foo.textContent = 'πŸ¦„';