hasClass-vs-is (v19)

Revision 19 of this benchmark created by HBender on


Preparation HTML

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

Setup

var element = $('div');

Test runner

Ready to run.

Testing in
TestOps/sec
hasClass
if( element.hasClass('class1') || element.hasClass('class2') || element.hasClass('class3') || element.hasClass('class4') || element.hasClass('class5') ) {
  console.log("hasClass");
}
ready
is
if( element.is('.class1, .class2, .class3, .class4, .class5') ) {
  console.log("is");
}
ready

Revisions

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