Setting a couple styles on an element with properties vs setAttribute

Benchmark created on


Preparation HTML

<div class="my-el"></div>

Setup

const myEl = document.querySelector('.my-el');

Test runner

Ready to run.

Testing in
TestOps/sec
object properties
myEl.style.top = "100%"
myEl.style.opacity = "100%"
ready
setAttribute
myEl.setAttribute("style", "top: 100%; opacity: 100%")
ready

Revisions

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