unicorn/prefer-dom-node-text-content Style
What it does
Enforces the use of .textContent over .innerText for DOM nodes.
Why is this bad?
There are some disadvantages of using .innerText.
.innerTextis much more performance-heavy as it requires layout information to return the result..innerTextis defined only for HTMLElement objects, while.textContentis defined for all Node objects..innerTextis not standard, for example, it is not present in Firefox.
Examples
Examples of incorrect code for this rule:
javascript
const text = foo.innerText;Examples of correct code for this rule:
javascript
const text = foo.textContent;How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny unicorn/prefer-dom-node-text-contentjson
{
"rules": {
"unicorn/prefer-dom-node-text-content": "error"
}
}