7 reasons why you really should learn jQuery »
FERDY CHRISTANT - FEB 2, 2009 (06:06:39 PM)
1. jQuery seperates behavior from markup
In HTML markup it is still quite common to see things like this:
<form id="myform" onsubmit=return validate();" >
Even though the validate() function can be placed in an external file, in effect we are still mixing markup with logic and events here. jQuery allows you to completely seperate the two. With jQuery, the markup would look like this:
Next, the seperate JS file will contain the following event subscription code:
...your code here
2. Write less, do more
That little snippet loops through all <p> elements with the class "neat" and then adds the class "ohmy" to it, whilst slowly showing the paragraph in an animated effect. No browser checks, no loop code, no complex animation functions, just one line of code!
4. It is a "standard"
JQuery is not an official standard, let that be clear. However, the industry support for jQuery is overwhelming. Google uses it, and even hosts it for you. Dell, Digg, Wordpress, Mozilla and many others use it too. Microsoft is even shipping jQuery with Visual Studio. With so much weight behind this framework, you can consider it a safe choice for the future, and a safe bet to invest time in.
6. It costs you little time
Of course it will cost you time to truly learn jQuery, especially if you will be writing lots of code or even your own plugins. However, you can do this in bits and pieces, there are tons of examples out there and it is really easy to get started. My advise is to first have a look in the plugin pool before you code something yourself. Next, have a look at the actual plugin code to see how it works. In short, learning jQuery is no huge investment, you can be productive right away and increase your skill in small increments.
What is not good about jQuery
Of course jQuery is not perfect. So far, I have experienced the following jQuery caveats:
- Not backwards compatible. Each new release is not by definition backwards-compatible with earlier releases. For example, sometimes some kind of selectors are deprecated. Instead of keeping them supported, jQuery simply removes them from the new release. This can break your code or that of plugins.
- Plugins-compatibility. Related to the previous point: when there is a new jQuery release and you want to upgrade, it will depend on your plugin author whether you can upgrade. Quite often existing plugins will break in the newest jQuery release. The more plugins you use, the bigger the chance this will happen. I once fixed a 3rd party plugin because I wanted to upgrade to jQuery 1.3, so you do not always have to wait for others.
- You can quite easily come in a conflicted state when you use multiple plugins on the same page, particularly when they tie to the same event or selectors. This is not due to jQuery itself, but still a problem that is hard to debug and fix.
- JQuery does not leave me with an impression of stability. It does not crash my browser, I'm talking about their release policy. Just days after the major new release 1.3, a bug fix release 1.3.1 was released. They also remove functionality that they classify as deprecated, potentially breaking a lot of code. I'm hoping these kind of breaking changes will be limited in the future.
- Out of the big frameworks, the jQuery core library has relatively poor support for animation and effects. However, in practice this is not problem at all. There is a seperate jQuery UI project and tons of plugins for these kind of things.
My opinion is that if you have these questions:
- If so, which one?
My answers would be "yes", and "jQuery". This is not to say the other frameworks are not good, it's just that jQuery looks like the most safe and rewarding investment of your time.
Do you agree?