Sunday, July 18, 2010

Programs I love - Today's program - jQuery

Just so that I don't forget, I've decided to blog about programs that I really use and love. It's not important if anybody reads it ('cause this is basically my web "log" :D)

They say, a programmer can only be known by his work. So is the case with John Resig ( His program - jQuery (, the write less and do more library that he wrote is a beautiful Javascript program. Beautiful, because it really works and is really small. So what is it?

jQuery's a Javascript program library that allows you to write your own Javascript code in a compact fashion. One common task in Javascript programs is to access specific elements on a page (for example, a div with an id="something"). jQuery provides easy (and new) ways to access them using what are called Selectors. These selectors are the same that are used in CSS for styling. So for example, if you styled a div by giving its class="someClass" attribute, jQuery allows you to access this element using jQuery(".someClass") . But that's not all - the object returned by jQuery(".someClass") is actually a wrapper over the page DOM object, and exposes a number of functions of its own. For example, it provides a click( ) function which takes in as argument, a handler function (basically, the functional programming approach) which gets called whenever the element is clicked.

Another important thing that jQuery does to compact the code is to use chaining of objects. So, if you've written jQuery(".someClass").click(function() {...}) , and you would like to do some more things to the same object, then you basically add a dot and continue jQuery(".someClass).click(function() {...}).hide( ) for example.

jQuery also provides a number of plug-ins that make a programmer's life easy. CSS is often used to style elements on a web page. jQuery provides easy ways to create good looking UI elements. For example, the Accordion navigator which is very useful for showing many categories of links in a compact manner, can be very easily built on a web page using jQuery(...).accordion( ). It only requires that the content be laid out as a hierarchical list (<ul>) tags. The good thing about it is that if for any reason (like if the browser doesn't support Javascript), jQuery doesn't work, the page still looks okay, because, it is still just an unordered list on the page.

All these things make jQuery a very handy program for creating web pages. The best thing, however, about jQuery is that it is cross-browser. This is very very important for web applications and pages that need to render on different browser, the likes of IE6, and Safari, and Opera, etc. jQuery just works.

Behind the scenes, when jQuery uses another library called the sizzleJS library which provides the basic selector functionality.

Oh! and one doesn't really have to write jQuery(...) everywhere.. One can simply use $(...) everywhere instead.


Blog Archive

About me

A soul possessed forever...