Test name | Executions per second |
---|---|
className | 15119.3 Ops/sec |
setAttribute | 12363.8 Ops/sec |
classList | 9843.9 Ops/sec |
<div id="foo"></div>
var element = document.getElementById('foo');
var i = 1000;
while (i--) {
element.className = "bar";
}
var i = 1000;
while (i--) {
element.setAttribute("class", "bar");
}
var i = 1000;
while (i--) {
element.classList.add("bar");
}