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

Revision 20 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ol>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
  <li>
    Item
  </li>
</ol>
<script>
  var $li = $('li');
</script>

Test runner

Ready to run.

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

Revisions

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