innerHTML vs innerText vs nodeValue vs textContent (v41)

Revision 41 of this benchmark created on


Preparation HTML

<div id="d"></div>
<span id="s"></span>
<script>
  var p = document.querySelector('p.meta'); // Any visible element on that page that contains some text.
  var d = document.getElementById("d");
  var s = document.getElementById("s");
  var t = "abcd1234";
  console.log(p,d,s,t);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
innerText - div
d.innerText = t;
ready
innerText - span
s.innerText = t;
ready
innerHTML - div
d.innerHTML = t;
ready
innerHTML - span
s.innerHTML = t;
ready
childNodes[0].nodeValue - div
d.childNodes[0].nodeValue = t;
ready
childNodes[0].nodeValue - span
s.childNodes[0].nodeValue = t;
ready
firstChild.nodeValue - div
d.firstChild.nodeValue = t;
ready
firstChild.nodeValue - span
s.firstChild.nodeValue = t
ready
textContent - div
d.textContent = t;
ready
textContent - span
s.textContent = t;
ready
textContent - visible p
p.textContent = t;
ready
innerText - visible p
p.innerText = t;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.