text content
JavaScript performance comparison
Info
Observation: .textContent ||.innerText order does matter in modern browsers. IE doesn't care, so put textContent first always.
Note: data, nodeValue and innerHTML are only included out of curiosity.
Preparation code
<div id="text">content to be retrieved</div>
<script>
var elem = document.getElementById("text");
var node = elem.firstChild;
</script>
Preparation code output
content to be retrieved
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
innerHTML |
|
pending… |
textContent || innerText |
|
pending… |
innerText || textContent |
|
pending… |
data |
|
pending… |
nodeValue |
|
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 galambalazs
- Revision 2: published by galambalazs
- Revision 3: published by galambalazs
- Revision 9: published by aeosynth
- Revision 10: published by Mayhem
- Revision 11: published
1 comment
Notice how huge the difference can be: