Does this adversely affect browser performance to assign a class name to the css class attribute of an element if the class has never been defined?
It is unusual to use class names for selectors with jQuery. I usually use a class that is used only to select items and never defines a class anywhere.
I assume most browsers will look for a css class definition, and could you somehow shorten the search if the style were defined?
I understand that css styles are compiled together before the page elements are displayed. This is why it is important to keep all CSS definitions together, rather than sharing them with script tags, as this causes most browsers to recompile CSS every time they mix with other definitions. The consequences of this can be serious enough for the page to display before applying the style.
However, in practice, I would suggest that the performance difference between the definition or absence of a CSS class definition is negligible, if any.
source share