One thing that is not talked about too much is how to preserve the style from your behavior, i.e. stylize the material like $('element').css({color: 'purple'}) , from your Javascript, when it is possible. For reasons of aesthetics of the code, as well as general sanity, I found it better to make code with style changes by updating the class values. In other words, do not think in the code that something should be "purple" - think that it should be "regal" or "peculiar" or "peculiar ugliness":
$('.sections li.updated').each(function() { // ... if (thingsLookRight) $(this).addClass('kind-of-ugly'); // ... });
Then your CSS can take over:
li.updated.kind-of-ugly { color: purple; }
Now you can make small style tricks up to ugly whenever you want, without having to mess up your Javascript. Make the font larger, make it hidden, whatever; the logic and action in the code remain unchanged.
Similarly, you can do awesome things using parent / child class relationships in CSS to make your behavior simple, fast, and styleless.
source share