hasClass-vs-is (v4)

Revision 4 of this benchmark created on


Preparation HTML

<span class="class5">
  Element
</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Setup

var element = $('span');

Test runner

Ready to run.

Testing in
TestOps/sec
hasClass
if (element.hasClass('class1') || element.hasClass('class2') || element.hasClass('class3')) {
  console.log("hasClass");
}
ready
is
if (element.is('.class1, .class2, .class3')) {
  console.log("is");
}
ready
loop
var selectors = ['class1', 'class2', 'class3'];
for (i in selectors) {
  if (element.hasClass(selectors[i])) {
    console.log("loop")
    break;
  }
}
ready

Revisions

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