As you most likely already know, it's simple in JQuery to select all elements in the document that have a specific CSS class, and then, using chaining, assign common event handlers to the selected elements:
$(".toolWindow").click(toolWindow_click);
$(".toolWindow").keypress(toolWindow_keypress);
As usual the class "toolWindow" is also normally defined in CSS and associated with some visual styles:
.toolWindow{
color:blue;
background-color:white;
}
The class attribute is now responsible for indicating not just the appearance (visual state) of the element, but also the behaviour. As a result, I quite often use this approach and define CSS class names more as pseudo object oriented classes then visual only CSS classes. In other words, each class represents both state (CSS styles) and behaviour (events).
In some cases I have even created classes with no visual styling and simply use them as a convenient way to assign behaviour to elements.
Moreover, the jQuery LiveQuery plugin (and the live() built-in function) make this approach even more effective by automatically binding events to dynamically created elements belonging to a specificed class.
Of late I am primarily using class names as defining a common set of behaviour for associated DOM elements and only later using them to define a visual style.
Questions: Is this a terrible misuse of the CSS "class" attribute, if so why?
On the other hand, perhaps it is a perfectly valid approach to further implementing "separate of concerns" and improving the maintainability of HTML/DHTML pages?