jQuery hover vs. toggle

JavaScript performance comparison

Test case created by Tomas

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<style>
  .border { border:5px solid black; }
</style>
<img src="https://twimg0-a.akamaihd.net/profile_images/410995499/google_logo_normal.jpg"
alt="logo" />
<img src="https://twimg0-a.akamaihd.net/profile_images/410995499/google_logo_normal.jpg"
alt="logo" />
<img src="https://twimg0-a.akamaihd.net/profile_images/410995499/google_logo_normal.jpg"
alt="logo" />
<img src="https://twimg0-a.akamaihd.net/profile_images/410995499/google_logo_normal.jpg"
alt="logo" />
<img src="https://twimg0-a.akamaihd.net/profile_images/410995499/google_logo_normal.jpg"
alt="logo" />
<img src="https://twimg0-a.akamaihd.net/profile_images/410995499/google_logo_normal.jpg"
alt="logo" />
<img src="https://twimg0-a.akamaihd.net/profile_images/410995499/google_logo_normal.jpg"
alt="logo" />
<script>
Benchmark.prototype.setup = function() {
    $('img').unbind();
};
</script>

Preparation code output

logo logo logo logo logo logo logo

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery Hover
$("img").hover(

function() {
  $(this).addClass("border");
}, function() {
  $(this).removeClass("border");
});
pending…
jQuery Toggle On
$("img").on("hover", function() {
  $(this).toggleClass("border");
});
pending…
jQuery Toggle Hover
$("img").hover(function() {
  $(this).toggleClass("border");
});
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

Add a comment