What’s New in jQuery 1.7?

First of all, a VERY HAPPY NEW YEAR to all the readers!!!

It has been a while since I wrote about the newer versions of any libraries or browsers. Only yesterday, I took a look at jQuery 1.7.1, which now comes with WordPress 3.3. The jQuery 1.7 was released on 3rd November 2011. While a bug fix version, jQuery 1.7.1 was released on 21st November 2011. The popular open source JavaScript library comes with new API for event handling, improvements in performance, Asynchronous Module definition and removal of some non-standard features, etc.

Improved Delegate Event Performance

Realizing the importance of event delegation, the jQuery team made optimizations in the jQuery core. These optimizations doubled the performance of delegate event. When the events are delegated to child elements, those child elements should be closest to the element (/s) that are actually firing the events. The core optimizations are aimed at faster event delegation.

New Event API

The new .on() and .off() APIs bring together all the ways of attaching events to a document in jQuery. The generalized syntax is

$(elements).on(events [, selector] [, data] , handler);

$(elements).off([ events ] [, selector] [, handler]);

Though, all the event delegation methods are still present in jQuery 1.7, but the jQuery team recommends the use of .on() and .off().

An example of binding a click event in before version 1.7 and version 1.7 is illustrated below:

$("a#refulz").click(Handler);  // Click event before jQuery 1.7

$("a#refulz").bind("click", Handler); // Binding click event before jQuery 1.7

$("a#refulz").on("click", Handler); // Click event in jQuery 1.7

Similar example for .delegate() and .undelegate() methods is shown below:

$('.container').delegate('a.refulz, 'click', Handler);

$('.container').undelegate('a.refulz, 'click', Handler);

//Above code can be replaced by the following code in the version 1.7

$('.container').on('click', 'a.refulz, Handler);

$('.container').off('click', 'a.refulz, Handler);

The .one() Method

Many times, an action is required only once. So, if you want an event to run only once and the detach, then you can use the new .one() method. The attached action is automatically detached after one execution.

.one(events [, selector] [, data], Handler)

For further reading, please visit the official documentation.

Support for HTML5 Tags in Older Browsers (IE6, IE7, IE8)

The older browsers do not understand the new HTML5 tags like <header>, <article>, etc. Moreover, they remove any such tags encountered in the HTML. With jQuery 1.7, the .html() method adds support for HTML5 tags on older browsers. However, additional libraries like HTMLShiv or Modernizr will be required for interpretation of those tags by the browsers.

New Callback Object

The jQuery.Callbacks() object returns a multi-purpose object that can be used to manage callback lists. The object provides a generalized way to queue and trigger a series of handlers. The jQuery.Deferred() is extended with new progress handlers and notification methods that call those handlers. Deferred are now implemented using the jQuery.Callbacks() object, which provides a generalized way of queuing and triggering a series of handlers.

Asynchronous Module Definition (AMD)

jQuery now supports the Asynchronous Module Definition (AMD) for defining modules and dependencies. The jQuery 1.7 is not a script loader itself; it cooperates with AMD-compliant loaders such as RequireJS or curl.js, so it can be loaded dynamically. The crucial .ready() event can be controlled by the loader itself. An AMD-compliant loader can load an unmodified version of jQuery 1.7 from a CDN such as Google’s or Microsoft’s.

jQuery.isNumeric()

The method detects numeric argument. If the argument is not numeric, the method tells whether it can be converted to a numeric value.

Other changes

  1. The stacked toggling animations such as .slideToggle() or .fadeToggle() now work fine.
  2. The event.layerX and event.layerY methods have been removed.
  3. Other undocumented methods that are removed from jQuery 1.7 are jQuery.isNaN() and jQuery.event.proxy().

For a completed list of fixes and miscellaneous enhancements, please refer to the complete release notes and change-log.

Downloading jQuery 1.7.1

The latest version of jQuery can be downloaded from jQuery website. The minified and the development version are available for download. The hosted copies of jQuery CDN can also be hot-linked from Google, Microsoft and jQuery CDN.

2 Responses to “What’s New in jQuery 1.7?”

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>