Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Chrome 63
Linux
Other
2025 years ago
Test name Executions per second
Pure JS .innerText 494806.5 Ops/sec
Pure JS .innerHTML 1358860.2 Ops/sec
Pure JS .textContent 2827669.0 Ops/sec
jQuery .text() 622250.1 Ops/sec
jQuery .html() 462312.2 Ops/sec
jQuery .find().text() 359178.8 Ops/sec
jQuery .find().html() 281811.8 Ops/sec
HTML Preparation code:
AخA
 
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"><script>
2
<script>jQuery.noConflict();</script>
3
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/7.0.3/cash.min.js"></script>
4
<div id="foo">Hello World</div>
Tests:
  • Vanilla JS .innerText

     
    var el = document.getElementById("foo");
    var text = el.innerText;
  • Vanilla JS .innerHTML

     
    var el = document.getElementById("foo");
    var text = el.innerHTML;
  • Vanilla JS .textContent

     
    var el = document.getElementById("foo");
    var text = el.textContent;
  • Vanilla JS (querySelector) .innerText

     
    var el = document.querySelector("#foo");
    var text = el.innerText;
  • Vanilla JS (querySelector) .innerHTML

     
    var el = document.querySelector("#foo");
    var text = el.innerHTML;
  • Vanilla JS (querySelector) .textContent

     
    var el = document.querySelector("#foo");
    var text = el.textContent;
  • Vanilla JS (querySelectorAll) .innerText

     
    var el = document.querySelectorAll("#foo");
    var text = el.innerText;
  • Vanilla JS (querySelectorAll) .innerHTML

     
    var el = document.querySelectorAll("#foo");
    var text = el.innerHTML;
  • Vanilla JS (querySelectorAll) .textContent

     
    var el = document.querySelectorAll("#foo");
    var text = el.textContent;
  • Cash .text

     
    var text = $("#foo").text();
  • Cash .html

     
    var text = $("#foo").html();
  • jQuery .text()

     
    var text = jQuery("#foo").text();
  • jQuery .html()

     
    var text = jQuery("#foo").html();
  • jQuery .find() .text()

     
    var text = jQuery(document).find("#foo").text();
  • jQuery .find() .html()

     
    var text = jQuery(document).find("#foo").html();