I have a table where I show/hide a full column by jQuery via a CSS class that doesn't exist:
"CSS class" is a misnomer;
class is an attribute (or a property, in terms of scripting) that you assign to HTML elements. In other words, you declare classes in HTML, not CSS, so in your case the "target" class does in fact exist on those specific elements, and your markup is perfectly valid as it is.
This doesn't necessarily mean that you need to have a class declared in the HTML before you can use it in CSS either. See ruakh's comment. Whether or not a selector is valid depends entirely on the selector syntax, and CSS has its own set of rules for handling parsing errors, none of which concern the markup at all. Essentially, this means HTML and CSS are completely independent of each other in the validity aspect. (This is also why a CSS ID selector matches any element with the given
id attribute regardless of whether the ID was determined to be unique and thus whether the HTML is conforming.)
Once you understand that, it becomes quite clear that there is no side effect of not defining a
When you write a CSS rule with a class selector, all you're saying is "I want to apply styles to elements that have this class." Similarly, when you write a script to retrieve elements by a certain class name, you're saying "I want to do things with elements that have this class." Whether or not there are elements with the class in question is a separate issue altogether.
1 The only situation I'm aware of where an empty CSS rule like that is necessary is when some browsers refuse to apply certain other rules properly as the result of a bug; creating an empty rule will cause those other rules to be applied for some reason. See this answer for an example of such a bug. However this is on the CSS side and therefore should have nothing to do with the markup.