nodeValue vs innerHTML and textContent. How to choose? [duplicate]

Differences between textContent/innerText/innerHTML on MDN.

And a Stackoverflow answer about innerText/nodeValue.

Summary

  1. innerHTML parses content as HTML, so it takes longer.
  2. nodeValue uses straight text, does not parse HTML, and is faster.
  3. textContent uses straight text, does not parse HTML, and is faster.
  4. innerText Takes styles into consideration. It won’t get hidden text for instance.

innerText didn’t exist in firefox until FireFox 45 according to caniuse but is now supported in all major browsers.

Leave a Comment