hidden vs. $.hide() vs. class

JavaScript performance comparison

Test case created by Greg Tyler

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style>.hidden { display:none; }</style>
<div id="first-div">Div contents</div>
      
<script>
Benchmark.prototype.setup = function() {
  var div = document.getElementById('first-div'),
      $div = $('#first-div');

};
</script>

Preparation code output

<style>.hidden { display:none; }</style> <div id="first-div">Div contents</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
$div.hide();
$div.hide();
pending…
div.classList.add('hidden');
div.classList.add('hidden');
pending…
$div.addClass('hidden');
$div.addClass('hidden');
pending…
div.hidden = true;
div.hidden = true;
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

Div contents