SteveClason.com

 

JavaScript Articles

jQuery 1.6: Changes to API

This list of changes to the jQuery API in version 1.6 is taken directly from the jQury website here. I only wrote it up so I had a small chance of remembering them.

New Features

deferred.always()
Add handlers to be called when the Deferred object is either resolved or rejected.
deferred.pipe()
Utility method to filter and/or chain Deferreds.

jQuery.Deferred() is a utility object introduced in jQuery 1.5 that increases the flexibility available in utilizing callback functions. Callbacks are very common in JavaScript and jQuery, ubiquitous, for instance, in asynchronous operations like jQuery.ajax(), when a function is invoked upon successfull receipt of the request. Oversimplified, the Deferred() object provides for a queue of callback functions and means to manage how they are fired. jQuery 1.6 adds these two new methods to the object. See http://api.jquery.com/category/deferred-object/ for the official jQuery description of the object.

:focus selector
New in 1.6, this selects an element if it is currently focused, so $("input:focused) selects any input element that is currently focused.
jQuery.holdReady()
Normally, the jQuery ready event fires as soon as the DOM is ready--this new method allows you to delay that event until some other event has transpired, in case, for instance, you want to hold the ready event until a plugin has finished loading. Handy, though maybe not very often.
.promise()
Often a number of relatively long-duration actions are taken on a set of elements, animations are the common example. The promise() method allows the programmer to attach to a set of elements a function to be performed after all of the animations are done, so that, for instance, after a bunch of elements are dynamically moved around on a page an announcement can be made that all of the moving has been concluded.
.prop()
This new method gets the property value for the first element in the matched set. It was added to remove some inconsistencies in the .attr() method, which sometimes would consider properties of an element as well as attributes. That latter method has been changed (see below) to accommodate this new method. Note that it only returns the value of the first match--some looping mechanism is needed to gather a bunch of them.
.removeProp()
This new method removes a property from each element in the set of matched elements, so, you could use $("input").removeProp("checked") to uncheck all the checkboxes on a form.

Revised features

.attr()
As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop() method. The usage for .attr() has changed on 1.6 because of the introduction of the .prop() method (see above).
.find()
Prior to version 1.6, the .find() method took as its argument a selector, just as you would pass to the jQuery function ($()), so $("#test").find(".red") gets all descendants of the element with id="test" that have class="red". With Version 1.6, you can also filter the descendants using an object or an element. So, var items = $("li"); $("#list").find(items); is the same as $(#list li) , and var item = $("li#what"); ("#list).find(item) is the same as $("#list li#what").
.is()
Formerly, this method allowed you to test a set of elements against a selector, returning true if there was a match. In 1.6, you can test that set of elements against a function, an object, or an element, still returning true of there is a match. There are good examples here.
.map()
Similar to the changes made to .find().is(), the changes in version 1.6 extend the usefulness of the method by allowing not just arrays to be mapped to new arrays, but also JavaScript objects to be mapped to either a new array or a new object.
.undelegate()
Undelegats allows you to remove event handlers from elements that have been bound using .delegate(). The change in 1.6 allows all bound events in a namespace to be removed, as well as events of a specific event type.