ClassList versus ClassName (v17)

Revision 17 of this benchmark created on


Preparation HTML

<div id="foo"></div>
<script>fooEl = document.getElementById('foo');</script>

Setup

fooEl.className = ' aaaa bbbb cccc dddd '; 
  //note the leading and trailing spaces

Test runner

Ready to run.

Testing in
TestOps/sec
classList.remove
fooEl.classList.remove('aaaa');
ready
className.replace
fooEl.className = fooEl.className.replace('aaaa ', ' ');
ready
classList.add
if( fooEl.className.indexOf('zzzz') === -1 ){
fooEl.classList.add('zzzz');
}
ready
className +=
if( fooEl.className.indexOf(' zzzz') === -1 ){
    fooEl.className += ' zzzz';
}
ready
remove
if( fooEl.className.indexOf('zzzz') !== -1 ){
    fooEl.classList.remove('zzzz');
}
ready
replace
if( fooEl.className.indexOf(' zzzz') !== -1 ){
    fooEl.className = fooEl.className.replace(' zzzz', '');
}
ready

Revisions

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