Test name | Executions per second |
---|---|
className | 6404.0 Ops/sec |
setAttribute | 4516.2 Ops/sec |
classList | 3703.1 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");
}