Feature:

Top 5 reasons jQuery doesn't suck

By Bear Bibeault, Author, jQuery in Action

TheServerSide.com

Like spending time on a yacht, jQuery doesnʼt suck. Here are my top 5 reasons why.


5. Do you really want to spend your life writing if statements to deal with browser differences?
While the state of Cross-browser Difference Hell in 2011 has improved slightly over past
years, there are still tons of browser specifics we need to deal with. Someday all
browsers might follow the W3C standards so that client-side script can enjoy the "write
once, run anywhere" capability that we enjoy on the server, but that day hasn't arrived.
jQuery deals with the vast majority of browser specifics so that we don't have to. We
write to a single API and, with very few exceptions, things “just work” on all modern
browsers.


4. Events make the Web go around, and the different event models can make your head spin with it!
We canʼt escape event handling in modern web user interfaces -- we just canʼt. Even
web sites that just show pictures of kittens have gotten mighty fancy.
And one of the most frustrating areas with respect to cross-browser differences are the
various event models. Should we use the ubiquitous but limiting DOM 0 Event Model?
Should we use the more versatile DOM 2 Event Model in all but IE, and IEʼs proprietary
model? Arghhh! Back to tons of conditionals!
Not only does jQuery provide an event model that works across all browsers, it offers
event-focused features that make dealing with events almost fun!
We can define “live” events for elements that donʼt even exist yet, group event types
into namespaces to make them easier to manage as a group, or even define custom
events. The latter gives us a means to use a publish/subscribe model in script --
something we can immediately see vastly simplifies many things and reduces coupling.
We like that!


3. You know you want to create DOM elements on the fly, but the XML API blows chunks.
Creating, manipulating and removing DOM elements is the life-blood of any dynamic
web user interface, but the XML-centric API provided by the browsers is tedious in the
extreme!
jQuery provides a simple API that allows us to easily create DOM elements, blow them
away, move them around, or otherwise manipulate them in any way that we see fit.
By-by NodeList! Donʼt let the door hit ya!


2. Plug it in! Plug it in!
What would we do without the rich ecosystem thatʼs grown up around Java? Imagine
life without the 3rd-party libraries that make Java so much more than just the core
language and its libraries!
Similarly jQuery -- which was wisely engineered from the ground up with the ability to be
extended -- has a huge community of plug-in writers that have provided an incredibly
rich set of plugins to do just about anything we might want to do in our client-side
scripts.
Date pickers? Form validation? Fancy controls? Animation effects? Modal dialogs?
Social integration? No problem!
And if we canʼt find a plugin to do it (whatever it is), itʼs a snap to extend jQuery
ourselves.


1. Ajax is the bomb, but dealing with the nuances can make your brain explode!
Itʼs be hard to think of a technology thatʼs changed the face of web interfaces more than
Ajax. Most modern user interfaces either depend upon Ajax capabilities completely, or
could at least benefit from some level of Ajaxificiation.
But Ajax, like most other advanced browser features has complexities that can frustrate
the modern page author to the point of extreme hair pullage.
jQuery makes Ajax as simple as scrubbing the kitchen sink with, well, the other Ajax.
Simpler in fact -- sink scrubbing is hard work. Ajax with jQuery is not.
jQuery handles all the cross-browser nuances of making and receiving Ajax requests
and responses, as well as offering such advanced capabilities as: centralizing error
handling and events, automatic JSON conversions, form value serialization, and a ton
of other freebies that make writing Ajax “by hand” seem like using stone knives and bear
skins.


Conclusion
You want to use jQuery. You really do! Admit it. All the cool kids are doing it. And with
very good reasons.

08 Feb 2011

Related Content

Related Resources