For example if I wanted to select some elements with a certain class using jQuery, and for that reason only, is it always expected that those classes SHOULD be defined in the css?.
<div class="xyz">
something
</div>
<div class="xyz">
something else
</div>
//with example jQuery
$(".xyz").hide();
//is it wrong no element 'xyz' is defined in css?
This is perfectly acceptable. As client side processing is becoming more common place (via jQuery, ExtJS, Prototype, etc), it makes sense to create efficient code that can use the powerful selector support provided by these libraries.
Using CSS classes and - depending on the case - IDs (unique!!) is perfectly fine and often the only solution to keep your HTML code valid while giving additional attributes used by scripts.
While using non-standard attributes often works fine, too, it will prevent your html code from validating and might cause issues in the future.
However, for some cases there might be attriutes which can be used, too - like rel
on links which is often used for scripts which modify link behaviour.
http://www.w3.org/TR/html401/struct/global.html#h-7.5.2 also mentions that class is general-purpose:
The class attribute, on the other hand, assigns one or more class names to an element; the element may be said to belong to these classes. A class name may be shared by several element instances. The class attribute has several roles in HTML:
- As a style sheet selector (when an author wishes to assign style information to a set of elements).
- For general purpose processing by user agents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With