jQuery CSS vs addClass speed

Benchmark created on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<style type="text/css">
.newClass {
background-color:red;
}
</style>

<div class="some preexisting classes"></div>

Teardown


    $('div').remove();
    $('body').append('<div class="some preexisting classes"></div>');
    
  

Test runner

Ready to run.

Testing in
TestOps/sec
Add class
$('div').addClass('newClass');
ready
Apply CSS
$('div').css({'background-color':'red'});
ready

Revisions

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