There are two ways of changing the style of an element: changing the element's
style properties or changing its
className. I feel that the second option should be a Best Practice, since it honours the separation of behaviour and presentation, where a
style change doesn't. After all, changing the
I wanted to make sure that changing the
className doesn't lead to performance problems. My new style vs. className benchmark test clearly shows that it doesn't. In fact, changing the
className is faster than changing the
style in all browsers but Safari.
I'm very glad of this outcome, since I can now solemnly declare changing the
className whenever you want to change the styles of an element a Best Practice, not only from a theoretical point of view, but also from a practical one.
I’m speaking at the following conferences:
Comments are closed.