show vs addclass

JavaScript performance comparison

Revision 7 of this test case created by Mohit Seth

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style type="text/css">
  .displayClass { display: block; }
</style>
<div id="test" style="display: none;">Hi</div>
<script>
  var elem = document.getElementById("test");
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
.show()
$(elem).show();
pending…
.addClass()
$(elem).addClass("displayClass");
pending…
.css()
$(elem).css('display','block');
pending…
raw js
elem.style.display="none";
pending…
jquery to raw js
$(elem)[0].style.display="none";
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:

0 comments

Add a comment