innerHTML vs innerText vs nodeValue vs textContent (v10)

Revision 10 of this benchmark created on


Preparation HTML

<div id="divinputme">
</div>
<span id="spaninputme">
</span>
<label id="labelinputme">
</label>
<script>
  var a = document.getElementById('divinputme'),
      b = document.getElementById('spaninputme'),
      c = document.getElementById('labelinputme'),
      s = '1,2,3,4';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
innerText - div
a.innerText = s;
ready
innerText - span
b.innerText = s;
ready
innerHTML - div
a.innerHTML = s;
ready
innerHTML - span
b.innerHTML = s;
ready
nodeValue - div
if(a.childNodes.length===0){
  a.textContent = " ";
}
a.firstChild.nodeValue = s;
ready
nodeValue - span
if(b.childNodes.length===0){
  b.textContent = " ";
}
b.firstChild.nodeValue = s;
ready
textContent - div
a.textContent = s;
ready
textContent - span
b.textContent = s;
ready
innerText - label
c.innerText = s;
ready
innerHTML - label
c.innerHTML = s;
ready
textContent - label
c.textContent = s;
ready

Revisions

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