JQuery find vs hasclass (v2)

Revision 2 of this benchmark created by Hien Nguyen on


Description

Needed to find out if find() was faster than hasClass()

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id="container">
    <div></div>
    <div class="demo">
    </div>
    <div></div>
    <div></div>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
find()
_.each($('#container div'), function(item){
    if ($(item).hasClass('star-selected')) {
        $(item).removeClass('star-selected');
    }
});
ready
hasClass()
$('#container').find('.star-selected').removeClass('star-selected');
ready

Revisions

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