jQuery addClass vs. attr( 'class' ) vs. prop('class') (v5)

Revision 5 of this benchmark created on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
addClass
var $d = $('<div>').addClass('foo');
ready
attr( 'class' )
var $d = $('<div>').attr('class', 'foo');
ready
prop( 'class' )
var $d = $('<div>').prop('class', 'foo');
ready
prop( 'className' )
var $d = $('<div>').prop('className', 'foo');
ready
Raw property
var $d = $('<div>')
$d.get(0).className = 'foo';
ready
Raw element and raw property
var d = document.createElement('div');
d.className = 'foo';
ready

Revisions

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