Some advice about diving into jQuery

I know, I know, I'm supposed to be busy switching VPS. I'm getting there. There's only so much I can do in a day. I just wanted to write a brief note about those interested in diving into jQuery. I'm probably exagerating percentages, but I want to say that 40% of jQuery development time is making sure your HTML / CSS is written correctly and as organized as you can possibly be with it.

If you spend at least that much, then you shouldn't run into any browser compatibility issues. 30% of your time is spent actually writing jQuery and 30% of your time is eyeballing the result in Firebug's console and fixing all the typos you made.

Remembering what the CSS rules are will be important. Id should be unique per page. So, if you have <a href="#" id="stuff">Text</a> - id="stuff" should not be found anywhere else. Even on a divs, paragraphs, etc. For those of us using a dynamic language (ColdFusion, PHP, etc), it can trip you up sometimes because you don't necessary think about the entire page when you're coding because you're within your application / module. I might even suggest that you come up with a naming scheme for whatever section you are in, such as id="footer_(whatever)" or id="app_row_(id)" or something to help you remember that this small chunk of code that you're looking at isn't necessarily the entire view that the end user is seeing. Classes can be used multiple times on a page. So, <a href="#" id="stuff" class="more">More Text</a> - class="more" can be used as many times as you want, even on other HTML elements.

In majority of the browsers, you can probably get away with multiple ids of the same name. In (at least) one of the browsers, it refuses to work (IE8). So, save yourself the headache. Stop rushing to get it out there and discipline yourself to writing valid (X)HTML / CSS code. jQuery will reward you for it and you'll have a long happy relationship.

Jason Dean

Jason Dean wrote on 10/15/09 10:42 AM

Great points Todd.

I'll say one other thing about jQuery that I have has personal experience with. Even when you are dealing with crappy HTML it has still be amazing to work with. I had to add error handlign once to terribly written HTML and jQuery made it a breeze.

Leave a comment


(required field)

(required field)