ClassList versus ClassName (v2)

Revision 2 of this benchmark created by Kashey on


Preparation HTML

<div id="foo"
></div>
<script>
 fooEl = document.getElementById('foo');
</script><script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

fooEl.className = 'aaaa bbbb cccc dddd';
  jFooEl = jQuery(fooEl);

Test runner

Ready to run.

Testing in
TestOps/sec
Class List
fooEl.classList.remove('ffff');    // actually adds
fooEl.classList.add('bbbb');    // duplicate
fooEl.classList.remove('eeee'); // not found
fooEl.classList.add('ffff');    // actually adds
ready
Raw Class Name
fooEl.className = 'aaaa bbbb cccc dddd';
fooEl.className += ' bbbb';
fooEl.className = 'aaaa bbbb cccc dddd bbbb';
fooEl.className += 'ffff';
ready

Revisions

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