jQuery.html() vs jQuery.text() vs el.innerHTML vs el.innerText
JavaScript performance comparison
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.9.0/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
contentthis is the content
this is the content
this
is the
contentTest runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
jQuery HTML multiple |
|
pending… |
jQuery Text |
|
pending… |
el.innerText |
|
pending… |
el.innerHTML |
|
pending… |
jQuery HTML selecting inner |
|
pending… |
jQuery HTML simple |
|
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:
- Revision 1: published by Henrique Gogó
- Revision 1: published by Henrique Gogó
- Revision 1: published by Henrique Gogó
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published
0 comments