Test name | Executions per second |
---|---|
style by property | 118.6 Ops/sec |
style by name | 123.3 Ops/sec |
setAttribute | 154.1 Ops/sec |
<div id="element" style="background:#555;color:#FFF;position:absolute;left:0;top:0;width:400px;height:100px;">
</div>
var elem = document.getElementById('element');
for (var i = 0; i< 1000 ; i++){
elem.style.width = i + 'px';
elem.style.height = i + 'px';
elem.style.top = i + 'px';
elem.style.left = i + 'px';
}
for (var i = 0; i< 1000 ; i++){
elem.style['width'] = i + 'px';
elem.style['height'] = i + 'px';
elem.style['top'] = i + 'px';
elem.style['left'] = i + 'px';
}
for (var i = 0; i< 1000 ; i++){
elem.setAttribute('style','width:' + i + 'px;height:' + i + 'px;top:' + i + 'px;left:' + i + 'px;');
}