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 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"><script>
<script>jQuery.noConflict();</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/7.0.3/cash.min.js"></script>
<div id="foo">Hello World</div>
var el = document.getElementById("foo");
var text = el.innerText;
var el = document.getElementById("foo");
var text = el.innerHTML;
var el = document.getElementById("foo");
var text = el.textContent;
var el = document.querySelector("#foo");
var text = el.innerText;
var el = document.querySelector("#foo");
var text = el.innerHTML;
var el = document.querySelector("#foo");
var text = el.textContent;
var el = document.querySelectorAll("#foo");
var text = el.innerText;
var el = document.querySelectorAll("#foo");
var text = el.innerHTML;
var el = document.querySelectorAll("#foo");
var text = el.textContent;
var text = $("#foo").text();
var text = $("#foo").html();
var text = jQuery("#foo").text();
var text = jQuery("#foo").html();
var text = jQuery(document).find("#foo").text();
var text = jQuery(document).find("#foo").html();