jQuery index vs hasClass (v16)

Revision 16 of this benchmark created by Pedro Guglielmo on


Description

Test which is faster, index compared to hasClass.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<section>
<article class="foo"></article>
<article class="bar"></article>
<article></article>
</section>

<script>
  var found = false;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
hasClass
if ($("article","section").hasClass("foo")) {
 found = true;
}
ready
index
if ($("article","section").index() == 0) {
 found = true;
}
ready

Revisions

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