toggle() vs. on()

JavaScript performance comparison

Test case created by Randy L

Preparation code

<div id="clicker" style="width: 150px; height: 150px; background-color: #00aa00; color: #eeeeee;">Click Me</div>
<div id="toHide" style="height: 100px; background-color: #aa0000"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

    

Preparation code output

<div id="clicker" style="width: 150px; height: 150px; background-color: #00aa00; color: #eeeeee;">Click Me</div> <div id="toHide" style="height: 100px; background-color: #aa0000"></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
Using click()
$(document).ready(function() {
  $('#clicker').click(function() {
    $('#toHide').hide();
  });
});
pending…
Using toggle()
$(document).ready(function() {
  $('#clicker').toggle(function() {
    $('#toHide').hide();
  }, function() {
    $('#toHide').show();
  });
});
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

Click Me