jQuery.html() vs jQuery.text() vs el.innerHTML vs el.innerText

JavaScript performance comparison

Revision 11 of this test case created

Info

Testing DOM vs native element content with retrieving text if extra html exists or not

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<div id="html"><div>this </div><span>is <div>the </div></span>content</div>
<div id="html2"><label>this is the content</label></div>
<div id="text">this is the content</div>
<div id="innerText">this is the content</div>
<div id="innerHTML"><div>this </div><span>is <div>the </div></span> content</div>

Preparation code output

this
is
the
content
this is the content
this is the content
this
is
the
content

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery HTML multiple
// async test
var o=$("#html");
for (var i = 0; i < 50; i++) {
  test = o.text();
}
pending…
jQuery Text
var o=$("#text");
for (var i = 0; i < 50; i++) {
  test = o.text();
}
pending…
el.innerText
var o=$("#innerText").get(0);
for (var i = 0; i < 50; i++) {
  test = o.innerText;
}
pending…
el.innerHTML
var o=$("#innerHTML").get(0);
for (var i = 0; i < 50; i++) {
  test = o.innerText;
}
pending…
jQuery HTML selecting inner
var o=$("#html2");
for (var i = 0; i < 50; i++) {
  test = o.find('label').text();
}
pending…
jQuery HTML simple
var o=$("#html2");
for (var i = 0; i < 50; i++) {
  test = o.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. Here’s a list of current revisions for this page:

0 comments

Add a comment