Run details:
Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
Safari 5
Windows 8
Other
6 years ago
Test name Executions per second
Pure JS .innerText 3625898.8 Ops/sec
Pure JS .innerHTML 751442.9 Ops/sec
Pure JS .textContent 322673.4 Ops/sec
jQuery .text() 79723.3 Ops/sec
jQuery .html() 137904.9 Ops/sec
jQuery .find().text() 66332.7 Ops/sec
jQuery .find().html() 101587.5 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");
    el.innerText = "New Hello World";
  • Vanilla JS .innerHTML

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

     
    var el = document.getElementById("foo");
    el.textContent = "New Hello World";
  • Vanilla JS (QuerySelector) .innerText

     
    var el = document.querySelector("#foo");
    el.innerText = "New Hello World";
  • Vanilla JS (QuerySelector) .innerHTML

     
    var el = document.querySelector("#foo");
    el.innerHTML = "New Hello World";
  • Vanilla JS (QuerySelector) .textContent

     
    var el = document.querySelector("#foo");
    el.textContent = "New Hello World";
  • Vanilla JS (QuerySelectorAll) .innerText

     
    var el = document.querySelectorAll("#foo");
    el.innerText = "New Hello World";
  • Vanilla JS (QuerySelectorAll) .innerHTML

     
    var el = document.querySelectorAll("#foo");
    el.innerHTML = "New Hello World";
  • Vanilla JS (QuerySelectorAll) .textContent

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

     
    $("#foo").text("New Hello World");
  • Cash .html

     
    $("#foo").html("New Hello World");
  • jQuery .text()

     
    jQuery("#foo").text("New Hello World");
  • jQuery .html()

     
    jQuery("#foo").html("New Hello World");
  • jQuery .find() .text()

     
    jQuery(document).find("#foo").text("New Hello World");
  • jQuery .find() .html()

     
    jQuery(document).find("#foo").html("New Hello World");