Test name | Executions per second |
---|---|
style by property | 105466.6 Ops/sec |
style by name | 107575.6 Ops/sec |
setAttribute | 110530.6 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');
i = 0;
elem.style.width = i + 'px';
elem.style.height = i + 'px';
elem.style.top = i + 'px';
elem.style.left = i + 'px';
i++;
elem.style['width'] = i + 'px';
elem.style['height'] = i + 'px';
elem.style['top'] = i + 'px';
elem.style['left'] = i + 'px';
i++;
elem.setAttribute('style','width:' + i + 'px;height:' + i + 'px;top:' + i + 'px;left:' + i + 'px;');
i++;