jQuery selector vs hasClass (v23)

Revision 23 of this benchmark created on


Description

Test which is faster, a selector including the class compared to hasClass.

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
is
if ($("body").is("foobar")) {
  found = true;
}
ready
hasClass
if ($("body").hasClass("foobar")) {
  found = true;
}
ready

Revisions

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