hasClass-vs-is (v15)

Revision 15 of this benchmark created by Max on


Preparation HTML

<span id="first" class="class1 class2">Element</span>
<span id="second" class="class2">Second Element</span>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

var firstElement = $('#first');
  var secondElement = $('#second');

Test runner

Ready to run.

Testing in
TestOps/sec
hasClass (having both classes)
if( firstElement.hasClass('class1') || firstElement.hasClass('class2') ) {
  console.log("hasClass");
}
ready
is (having both classes)
if( firstElement.is('.class1, .class2') ) {
  console.log("is");
}
ready
hasClass (having second class only)
if( secondElement.hasClass('class1') || secondElement.hasClass('class2') ) {
  console.log("hasClass");
}
ready
is (having second class only)
if( secondElement.is('.class1, .class2') ) {
  console.log("is");
}
ready

Revisions

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