classList.remove vs. className.replace(regEx, '')

Benchmark created by Deryck on


Description

Self-explanatory. Using native JS and only ID for selection.

Preparation HTML

<div id="jamesbond">
<span id="inner" class="duck goose turtle">Stranger things.</span>
</div>

Setup

var main = document.getElementById('jamesbond');
    main.className = 'page one two sweet';

Test runner

Ready to run.

Testing in
TestOps/sec
classList.remove()
main.classList.remove('two');
ready
className.replace(regEx, '')
main.className.replace(/two/, '');
ready
classList.add()
main.classList.add('fixed-menu');
ready
className +=
main.className.replace(/.$/, ' fixed-menu');
ready

Revisions

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