Skip to content

nodeTextContents

Prefer textContent over innerText for DOM nodes.

✅ This rule is included in the browser logical preset.

The textContent property should be preferred over innerText when accessing or setting the text content of DOM nodes. textContent is more performant because it doesn’t trigger a reflow, is more widely supported and standard across browsers, and has more predictable behavior.

innerText is aware of styling and won’t return text of hidden elements, which can lead to unexpected behavior in some cases. Additionally, innerText is slower because it requires layout information.

const text = element.innerText;
element.innerText = "Hello";
const content = node.innerText;
div.innerText = value;

This rule is not configurable.

If you specifically need the behavior of innerText (filtering out hidden elements or getting rendered text), then you should disable this rule for those specific cases.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.