Prefer .textContent
over .innerText
​
💼 This rule is enabled in the ✅ recommended
config.
💡 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.
Fail ​
js
const text = foo.innerText;
js
const {innerText} = foo;
js
foo.innerText = '🦄';
Pass ​
js
const text = foo.textContent;
js
const {textContent} = foo;
js
foo.textContent = '🦄';