Summary:

  • nodeValue is a little more confusing to use, but faster than innerHTML
  • innerHTML parses content as HTML and takes longer(output text/html)
  • textContent uses straight text, does not parse HTML, and is faster(output text/plain)
  • innerText takes styles into consideration. It won’t get hidden text for instance.

node.textContent

The Node.textContent property represents the text content of a node and it descendants.

Syntax

example.textContent ="<a href='...'>textContent</a>"
will output <a href='...'>textContent</a>

Differences from innerText

  • textContent gets the content of all elements, including