innerHTML vs innerText vs nodeValue vs textContent (v32)

Revision 32 of this benchmark created on


Preparation HTML

<div id="divinputme" style="position:absolute;left:10px;top:0">x</div>
<span id="spaninputme" style="position:absolute;left:110px;top:0">x</span>
<label id="labelinputme" style="position:absolute;left:210px;top:0">x</label>

Setup

var a = document.getElementById('divinputme'),
      b = document.getElementById('spaninputme'),
      c = document.getElementById('labelinputme');
  var s = '1,2,3,4';
  a.innerHTML = s;
  b.innerHTML = s;
  c.innerHTML = s;
  var an = a.firstChild,
      bn = b.firstChild,
      cn = c.firstChild;
  var ah = a.offsetHeight,
      bh = b.offsetHeight,
      ch = c.offsetHeight;

Test runner

Ready to run.

Testing in
TestOps/sec
innerText - div
a.innerText = s;
ready
innerText - span
b.innerText = s;
ready
innerText - label
c.innerText = s;
ready
innerHTML - div
a.innerHTML = s;
ready
innerHTML - span
b.innerHTML = s;
ready
innerHTML - label
c.innerHTML = s;
ready
textContent - div
a.textContent = s;
ready
textContent - span
b.textContent = s;
ready
textContent - label
c.textContent = s;
ready
nodeValue - div
an.nodeValue = s;
ready
nodeValue - span
bn.nodeValue = s;
ready

Revisions

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