hasClass-vs-is (v18)

Revision 18 of this benchmark created on


Preparation HTML

<span class="class1">Element</span>
<span class="class2">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') ) {
}
ready
is
if( element.is('.class1') ) {
}
ready
match
if( element.attr('class').match(/class1/) ) {
}
ready
match + word boundaries
if( element.attr('class').match(/\bclass1\b/) ) {
}
ready

Revisions

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