jQuery text() vs. html()

JavaScript performance comparison

Revision 15 of this test case created by

Preparation code

<script src="https://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>
    

Preparation code output

<p id="text"> Test text </p>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
jQuery - html()
$text.html('add_html');
pending…
jQuery - text()
$text.text('add_text');
pending…
Vainilla Js - textContent or innerText
To_Text(jstext, 'vjs_text');
pending…
Vainilla Js - innerHTML (not a good way)
jstext.innerHTML = 'vjs_text';
pending…

Compare results of other browsers

Revisions

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

0 Comments

Test text