jQuery addClass(...) vs attr('class', ...) (v14)

Revision 14 of this benchmark created on


Preparation HTML

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

Setup

var list = $(".list:first")
    
    for (var i = 0; i < 1000; i++)
    {
       list.append($("</li>"));
    }
    
    $li = $(".li");

Test runner

Ready to run.

Testing in
TestOps/sec
addClass
$li.addClass('test').removeClass('test');
ready
attr class
$li.attr('class', 'test').removeClass('test');
ready

Revisions

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