After reading the answer to this question (How does adding a class work on an element with that class already?), it seems that using jQuery's .addClass('foo')
method is not problematic if the element already has the class foo
.
I wonder if the same holds true for the element.classList
method with .add
.
Specifically, I have a function called update()
that gets called whenever a range slider is adjusted - sometimes multiple times per second. Depending on the input given to update()
, I add and remove certain classes from an element.
If the input falls within a specific range consistently, I find myself repeatedly adding the same class.
So, my question is whether it is acceptable to allow elem.classList.add('foo')
to be executed, for example, 50 times in one second without causing any negative effects on user experience, memory usage, or processor load. Is this considered good practice?
Thank you.