hasClass vs is so (v7)

Revision 7 of this benchmark created on


Preparation HTML

<div id="foo">
  I am a DIV
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Setup

var a = $('#foo'),
      b = a.get(0);

Test runner

Ready to run.

Testing in
TestOps/sec
is
a.is('.bar');
ready
className (regex)
/(^|\W)bar(\W|$)/ig.test(b.className);
ready
hasClass
a.hasClass('bar');
ready
className (string)
(' ' + b.className + ' ').indexOf(' bar ') !== -1
ready

Revisions

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