jQuery text() vs. html() vs [0] vs native

JavaScript performance comparison

Revision 32 of this test case created by Heavensrevenge

Preparation code

<script src="https://code.jquery.com/jquery-git2.min.js"></script>

<p id="text">Test text</p>
<input id="title" type="text" placeholder="Main Title">
      
<script>
Benchmark.prototype.setup = function() {
  var $text = $("#text");
  var $title= $("#title");

};
</script>

Preparation code output

<p id="text">Test text</p> <input id="title" type="text" placeholder="Main Title">

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
text()
$text.text();
pending…
html()
$text.html();
pending…
innerText
$text[0].innerText;
pending…
innerHTML
$text[0].innerHTML;
pending…
text().contains
$text.text().contains("Test text");
pending…
html().contains
$text.html().contains("Test text");
pending…
innerText.contains
$text[0].innerText.contains("Test text");
pending…
.text() set
$text.text("New Text");
pending…
.html() set
$text.html("New Text");
pending…
.prop set
$title.prop("value", "COMPLETELY New Title");
pending…
.prop get
$title.prop("value");
pending…
.val() set
$title.val("COMPLETELY New Title");
pending…
.val() get
$title.val();
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