jquery show/hide vs DOM style.display

JavaScript performance comparison

Test case created by cHao

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="testDiv">
 Who cares what's actually in this div?
</div>
      
<script>
Benchmark.prototype.setup = function() {
  function showWithJQuery(id) {
      $('#' + id).show();
  }
  function hideWithJQuery(id) {
      $('#' + id).hide();
  }
  
  function showWithoutJQuery(id) {
      document.getElementById(id).style.display = '';
  }
  function hideWithoutJQuery(id) {
      document.getElementById(id).style.display = 'none';
  }

};
</script>

Preparation code output

<div id="testDiv"> Who cares what's actually in this div? </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
showWithJQuery('testDiv');
hideWithJQuery('testDiv');
pending…
DOM only
showWithoutJQuery('testDiv');
hideWithoutJQuery('testDiv');
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 Comments

Who cares what's actually in this div?