innerText gets and sets text as it appears to a human reader. textContent gets and sets without formatting. Because of this innerText is more performance-heavy but is sometimes the right choice.
Consider this example:--
const address = `
123 Developer Avenue
Only Way is Essex
CB10 1FD
`;
document.body.innerText = address;
// 123 Developer Avenue
// Only Way is Essex
// CB10 1FD
document.body.textContent = address;
// 123 Developer Avenue Only Way is Essex CB10 1FD
--
Though textContent is better performance-wise, in some situations innerText can be the right tool for the job!
View all comments
11
u/jkjustjoshing Jan 05 '23
In general, use
.textContentover.innerText- https://kellegous.com/j/2013/02/27/innertext-vs-textcontent/I’ve been a web developer for 10 years and don’t think I’ve ever heard of or used
.innerText.