I suppose I should have expected to get roasted on that last post. It’s what I get for dipping my inexpert toes into a hotly-debated pool. So I’ll clarify my position thusly:
Yes, presentation should be separated from behavior. Yes, a form field achieves a state of focus through an event. Yes, events should ideally be handled by a scripting language, not CSS. Yes, using script to alter the appearance of focused fields functionally negates the need for CSS to do the same. Yes, I probably prefer to do it the easy way because I’m lazy, even if it means my layers blend just a tad.
However, what I was really thinking about was the user experience, not the purity of implementation. (The purest approach would probably be to not give focused fields any special graphic treatment at all, and leave them to be rendered by the user-agent’s default styling.) Altering the appearance of a focused form element is a usability enhancement, and all people deserve that improved experience if they’re able to experience it, even if they happen to be using Internet Explorer.
But in all this, there still seems to be some crossover between behavior and style: the event triggers the application of a presentational CSS class. If the onfocus
event were to trigger some other action, or manifest some other structural elements, or insert some semantically valuable attribute instead of a purely presentational class… obviously that’s the bailiwick of DOM scripting, and CSS has no business being in the picture.
In the specific example I gave (that of visually highlighting a focused element) is it really so wrong to use CSS for presentation? Is swapping presentational classes with JavaScript really the preferred behavioral solution to this presentational problem? Should :hover and :focus be summarily deprecated and abolished from the CSS spec? I’m still not entirely convinced, and I think it probably has to be considered on a case-by-case basis. So go easy on me, Jeremy, I’m getting better.