jQuery -- innerHTML === "" vs is(":empty"

JavaScript performance comparison

Revision 14 of this test case created by themoonrat

Preparation code

<script src="https://code.jquery.com/jquery-2.1.0.min.js">
</script>
<script>
var cachedJquery = $('#id');
</script>
<div class="test-element">
</div>
<div id="id" class="test-element">
</div>
<div class="test-element">
</div>
<div class="test-element">
</div>
<div class="test-element">
</div>
    

Preparation code output

<script> var cachedJquery = $('#id'); </script> <div class="test-element"> </div> <div id="id" class="test-element"> </div> <div class="test-element"> </div> <div class="test-element"> </div> <div class="test-element"> </div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
jQuery .html()
cachedJquery.text("MOONRAT");
pending…
innerText
cachedJquery[0].innerText = "MOONRAT";
pending…
innerHTML
cachedJquery[0].innerHTML = "MOONRAT";
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.

0 Comments