jQuery selector vs hasClass

JavaScript performance comparison

Revision 23 of this test case created by

Preparation code

<div class="foo"></div>
<script>
  var found = false;
  $("body").addClass("foobar");
</script>
    

Preparation code output

<div class="foo"></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
is
if ($("body").is("foobar")) {
  found = true;
}
pending…
hasClass
if ($("body").hasClass("foobar")) {
  found = 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