JQuery

JQuery is a new kind of Java Script Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write Java Script.

John Resig

JQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML. It was released in January 2006 at BarCamp NYC by John Resig. John Resig is a JavaScript Evangelist for the Mozilla Corporation and the creator and lead developer of the jQuery JavaScript library. This library's goal is to simplify the process of writing JavaScript code that is compatible with all web browsers. Both Microsoft and Nokia have announced plans to bundle jQuery on their platforms, Microsoft adopting it initially within Visual Studio for use within Microsoft's ASP.NET AJAX framework and ASP.NET MVC Framework whilst Nokia will integrate it into their Web Run-Time platform.

One of the major release of this library was on January 14, 2009 and it is version 1.3. This has introduced Sizzle Selector Engine into core. The lateset release is version 1.3.2 and is released on February 20, 2009.

You can download your own copy of jQuery from the Downloading jQuery page.

JQuery contains the following features:

  • DOM element selections using the cross-browser open source selector engine Sizzle, a spin-off out of jQuery project
  • DOM traversal and modification (including support for CSS 1-3 and basic XPath)
  • Events
  • CSS manipulation
  • Effects and animations
  • Ajax
  • Extensibility
  • Utilities - such as browser version and the each function.
  • JavaScript Plugins

The $ function - One of the critical concepts in any jQuery code is the so called '$' function. '$' is actually an 'alias' for the 'jQuery' namespace. jQuery provides a function for trimming strings. This function can be used as:

	str = "    jQuery     ";
	jQuery.trim(str); // returns "jQuery"
	

Or, it can also be used as:

	str = "    jQuery     ";
	$.trim(str); // returns "jQuery"
	

JQuery usually exists as a single JavaScript file, containing all the common DOM, Event, Effects, and Ajax functions. It can be included within any web page by using the following mark-up:

	<script type="text/javascript" src="/path/to/jQuery.js"></script>
	

The latest stable versions of jQuery can also be loaded using the Google AJAX Libraries API. This method of obtaining the library has many benefits including unified caching and decreased latency and can be included with the following mark-up:

  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  <script>
    google.load("jquery", "1.3.2");
  </script>
	

  • via the $ function, which is a factory method for the jQuery object. These functions, often called commands, are chainable; they each return the jQuery object
  • via $.-prefixed functions. These are utility functions which do not work on the jQuery object per se.

A typical workflow for manipulation of multiple DOM nodes begins with $ function being called with a CSS selector string, which results in the jQuery object referencing zero or more elements in the HTML page. This node set can be manipulated by applying instance methods to the jQuery object, or the nodes themselves can be manipulated. For example:

	$("div.test").add("p.quote").addClass("blue").slideDown("slow");
	

…finds the union of all div tags with class attribute test and all p tags with class attribute quote, adds the class attribute blue to each matched element, and then slides them down with an animation. The $ and add functions affect the matched set, while the addClass and slideDown affect the referenced nodes.

The methods prefixed with $. are convenience methods or affect global properties and behaviour. For example, the following is an example of the map function called each in jQuery:

  $.each([1,2,3], function() {
  document.write(this + 1);
  });

	

... writes 234 to the document.

Reference Articles