hasClass vs native (v8)

Revision 8 of this benchmark created on


Description

Test jQuery.hasClass vs native

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test" class="my-test"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
hasClass()
$('#test').hasClass("my-test")
ready
native
$('#test')[0].className.match(/^my-test$/)
ready
addClass
$('#test').addClass("selected")
ready
native 2
$('#test')[0].className = "selected"
ready
native - regex obj
var patt = "my-test";
$('#test')[0].className.match(new RegExp(patt));
ready
indexof
$('#test')[0].className.indexOf("my-test");
ready

Revisions

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