jquery is vs hasclass vs pure (v12)

Revision 12 of this benchmark created on


Preparation HTML

<a class="someClass" id="someElement" href="#">link</a>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var $t = $("#someElement");
  
  function hasClass(el, selector) {
   var className = " " + selector + " ";
  
   if ((" " + el.className + " ").replace(/[\n\t]/g, " ").indexOf(className) > -1) {
    return true;
   }
  
   return false;
  }

  function hasClassArray(el, selector) {
    var classArray = el.className.split(' ');
    return classArray.indexOf(selector) >= 0;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
is
$t.is("someClass");
ready
hasClass
$t.hasClass("someClass");
ready
pureJs
hasClass($t.get(0), 'someClass');
ready
pureJs using array
hasClassArray($t.get(0), 'someClass');
ready

Revisions

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