cssText vs style (v25)

Revision 25 of this benchmark created on


Description

Comparing the performance of using style against changing directly cssText. Also compared against with just adding a css classname.

Preparation HTML

<div id="element">
</div>
<style type=”text/css”>
  .newClass { left: 10px; top:50px; }
</style>

Test runner

Ready to run.

Testing in
TestOps/sec
element.style
var element = document.getElementById('element');
var left = 10;
var top = 50;
element.style.left = left + 'px';
element.style.top = top + 'px';
ready
element.cssText
var element = document.getElementById('element');
var left = 10;
var top = 50;
element.style.cssText = 'left: ' + left + 'px; top: ' + top + 'px;';
ready
change css class
 
ready

Revisions

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