hasClass-vs-is (v17)

Revision 17 of this benchmark created on


Preparation HTML

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

Setup

var element = $('span'),
      vElement = element[0];

Test runner

Ready to run.

Testing in
TestOps/sec
hasClass
if( element.hasClass('class1') ) {
  console.log("match");
}
ready
is
if( element.is('.class1') ) {
  console.log("match");
}
ready
match
if( element.attr('class').match(/class1/) ) {
  console.log("match");
}
ready
match on almost vanilla element
if( element[0].className.match(/class1/) ) {
  console.log("match");
}
ready
match on vanilla element
if( vElement.className.match(/class1/) ) {
  console.log("match");
}
ready

Revisions

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