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

Revision 11 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');
$li.removeClass('test');
ready
attr class
$li.attr('test', 'test');
$li.removeAttr('test');
ready

Revisions

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