A few days ago, I received this tweet:
I'd like a full, comprehensive blog post by @_dte about when to use JS and when to use CSS to accomplish the same things.
-- Logan Galla (@logangalla) January 5, 2012
I've thought about writing something on this topic for quite some time, but always chickened out when it came to sitting at my keyboard. I don't want this to seem like a "one true way" guide, but instead I'd like to offer insight into the thinking behind the decisions I make about CSS and JS, particularly when it comes to the interactive layer of a website. <!-- more -->
Stating the obvious
But my problem with this technique goes beyond the fact it's not reliable - it's the simplest example of the philosophical approach behind my JS vs CSS decisions.
And what about that blurry logical/visual line? What if you have visual changes when an action that involves logical processing is involved? Well, a combination of the two is the best solution in this case. Rather than injecting a large amount of inline CSS, I prefer adding or removing classes to the element in question, keeping visual appearance inside the CSS file(s).
Like I mentioned in the beginning, I don't want this to be a guide for anyone. You should do what you feel makes more sense to use. And if you feel like I'm doing something wrong, feel free to let me know - I'm easily persuaded, if you can show me a better alternative.