I’ve got a div
that’s intermittently hidden in my app.
<!-- Hidden -->
<div aria-hidden="true">...</div>
When making the div
visible I omit the aria-hidden
attribute, keeping the DOM clean and relying on the fact that the div
is visible by default.
<!-- Visible -->
<div>...</div>
Is there any performance differential between the previous approach where I omit the attribute altogether, and the next approach where I change the attribute’s value to false
?
<!-- Visible -->
<div aria-hidden="false">...</div>
I’m aware that if there’s a difference it’ll be small. Presumably still measurable, though. This is an academic question more than anything else.
2
Answers
I added a test for this here: https://jsperf.app/fapozi
Setting up the test with:
Test case 1 is:
Test case 2 is:
Here are the results for Firefox and Chrome on my machine
Results
Apparently using
removeAttribute
is slightly faster!Removing an attribute is faster: