Building A Relationship Between CSS & JavaScript

Offload some of the weight JavaScript carries onto CSS

jQuery, Prototype, Node.js, Backbone.js, Mustache and thousands of JavaScript microlibraries all combine into a single undeniable fact: JavaScript is popular. It’s so popular, in fact, that users often find themselves using it in places where another solution might be better in the long run.  Because JavaScript is so powerful, there are a lot of overlaps in capability between JavaScript and HTML (building document structure) and JavaScript and CSS (injecting style information).

 

CSS can hook into HTML with a variety of different selectors; this isn’t anything new. By using IDs, classes or any attribute you can think of (even custom attributes), you have easy access to style an element. But, as you move forward with JavaScript and build applications with highly interactive elements, it gets harder to not only keep HTML out of your JavaScript, but also to catch yourself before injecting style information into a document. You can probably all agree that blindly using a technology is a terrible idea. To keep the CSS out of the JavaScript you can use the behavior of jQuery’s hide() method.

Comments

Be the first to write a comment

You must me logged in to write a comment.