jQuery Cookbook Solutions and Examples for jQuery Developers

***** Feb102010

There is a lot to digest (ha!) in the JQuery Cookbook. I had never checked out books from O’Reilly’s Cookbook series, which are set up in a straightforward Problem, Solution(s), Discussion format. I was expecting a collection of sort of design-pattern “recipes”: things like “Create a sortable table with drag-and-drop functionality”. While this book does contain many concrete, practical examples of this type, there are also high-level problem/solution pairs that get at fundamental jQuery and Javascript concepts, such as how to make your code more readable and efficient.

JQuery Cookbook Contents

As with most JQuery books I’ve read, this one starts out with some basics and then a chapter on “Selecting Elements with jQuery”. Chapter 3 is sort of a miscellany, and Chapter 4 covers some of the jQuery utilities that can be extremely useful yet which the casual jQuery user (such as myself) aren’t very familiar with, such as JQuery.support, and JQuery.merge.

There is a lot going in in Chapter 5, including several principles for optimizing your code, and what $(this) really refers to in various contexts. Chapters 6, 7, 8, and 9 discuss Dimensions, Effects, and Events, and Advanced Events, respectively. Chapters 10 through 15 contain a higher proportion of those concrete examples, like enhancing forms, using jQuery plugins, and the JQuery UI library. Chapter 16 covers jQuery and Ajax, and it was the one I felt could have been longer. To be perfectly honest Chapters 16 and 17 seemed beyond my pay grade and I skipped them.

Highlights from the JQuery Cookbook

I had several “Aha!” moments when reading this book, starting early on on page 12. Here are three of my favorites:

  • This one may seem obvious, but having done a lot of “View > Source”, I can say I haven’t seen it used often. Essentially, jQuery wizard Cody Lindley points out that if we put our scripts before the closing </body> tag rather than in the head (which we know we should do from a speed optimization standpoint anyway) then there is no need to wrap everything in the ready() event, making for even faster code. Sweet!
  • I am now a little closer to understanding Javascript closures, thanks to recipe 5.2, though I’m still not sure why or if I need to understand them.
  • Not one but two methods for pre-styling (often hiding) elements on a page that you’ll later manipulate (or reveal) with Javascript. Page 180: add a a special class to a DOM element that is ready quickly, such as <html>: jQuery('html').addClass('hide-stuff');. Or, on page 280, use document.write() to dynamically write in a link to a special style sheet. Delicious!

Conclusion

The JQuery Cookbook contains clear explanations of both high-level JQuery/Javascript concepts and practical nuts-an-bolts examples. I would say it is not for absolute beginners, but makes an excellent follow-up to Learning Jquery.

Respond to this review

Author(s)Cody Lindley, many others
PublisherO'Reilly Media
Pages476
Published2009
ISBN-100596159773
Category
Tags
Rating*****

No comments yet…Be the first!

Comments are closed for this article.