jQuery text() vs. html() (v15)

Revision 15 of this benchmark created on


Preparation HTML

<script src="//code.jquery.com/jquery-1.8.2.min.js">
</script>
<p id="text">
  Test text
</p>
<script>
  var jstext = document.getElementById('text'),
      $text = $('#text'),
      To_Text;

  //feature check, modern browsers support .textContent
  if (jstext.textContent) {
    To_Text = function(elm, text) {
      elm.textContent = text;
    };
  } else {
    // ie < 9
    To_Text = function(elm, text) {
      elm.innerText = text;
    };
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery - html()
$text.html('add_html');
ready
jQuery - text()
$text.text('add_text');
ready
Vainilla Js - textContent or innerText
To_Text(jstext, 'vjs_text');
ready
Vainilla Js - innerHTML (not a good way)
jstext.innerHTML = 'vjs_text';
ready

Revisions

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