Thursday, April 29, 2010

jQuery Chaining

Source: jQuery Cookbook (Chapter 1)


The following code can be changed from this:

jQuery('div').hide();
jQuery('div').text('new content');
jQuery('div').addClass("updatedContent");
jQuery('div').show();


to this:

jQuery('div').hide().text('new content').addClass("updatedContent").show();


 

Behind the scenes, the elements previously selected before a jQuery method was applied are always returned so that the chain can continue.

No comments:

Post a Comment