jQuery is awesome

When I started my latest project a friend of mine asked me to look into using jQuery. I had played with MooTools a couple years ago and was mildly impressed, and I figured jQuery would be more of the same.

Boy was I wrong! For what I’m doing jQuery is way better than MooTools!

MooTools is basically two things:

  • A bunch of extensions for the standard javascript classes
  • A set of really nice UI widgets

jQuery is similar, but the approach is a lot different:

  • A tool for grabbing a collection of DOM elements.
  • A mechanism for manipulating the collection once you grab it.
  • And if you use jQuery UI, a set of really nice UI widgets

The core of jQuery is a simple CSS-like syntax for grabbing a collection DOM elements from the page.  It turns out that the ability to grab the DOM elements you need is actually a disproportionately large part of building a modern web app.  Don’t believe me?  Say you need to output a formatted table with even lines colored differently than odd lines.  Tradionally, this would mean crafting a CSS class named “even” and then writing server side code to determine if we were outputting an odd row or an even row.  If it is an even row then we would add a class=”even” to the tr tag.  This would all be done inside of a big loop outputting the table rows.

In jQuery I can just output the table without the “even” class and then add it with javascript after the fact with 1 line of code:

$('table > tr:even').addClass('even')

Boom! No need to write any server side code just to add a CSS class to alternate the background color of a row.

Leave a Reply

Your email address will not be published. Required fields are marked *