Before I dive on topic, I want to give you all a heads up that I will be posting a review of the book: "AJAX and PHP: Building Modern Web Applications 2nd Edition", by Packt Publishing. So far the book is great and has some nice chapters about jQuery, JSON, PHP and even XAMPP.
Now jQuery Enlightenment (jQE) isn't much of a book as it is a helpful PDF. It's not as long as your typical book, but it gets the job done in explaining jQuery and its core components. The topics that are covered in jQE range from Selectors, Traversal, DOM and Manipulation, Forms, Events, Plugins, AJAX, the Core and much more. The current edition of the book covers jQuery 1.3.2, and since 1.4 recently came out, I'm going to note any differences or problems that can be solved using 1.4 (if there are any).
The document is only a mere 123 pages (PDF pages to be precise), which may sound like a lot, but in actuality it isn't. Each chapter of jQE comes with code snippets, which have links to JsBin.com that allow you to run and test the snippet yourself. The snippets are also color coded to represent which areas of the code you should be focusing on and understanding. These features were probably the greatest thing about jQE and what sets it apart from regular books. It allows you to interact with the code first hand and makes it easier to understand once you see it in action (and you don't have to manually write it all too!). One caveat though is that the snippets use alert() for testing purposes, as they didn't want to rely on you having Firebug installed.
The book begins by talking about the jQuery core, of course. It states that jQuery should only be used in HTML standards mode, and not in quirks mode, as it has problems with rendering. One great aspect that I liked is its explanations of do's and don'ts and how to properly use jQuery to its full advantage. An example of this is to use the built in short hand code, and when to properly bind and invoke certain event handlers.
// You can get the current jQuery version by using the jQuery property
var version = $().jquery; // or $.fn.jquery
A feature that I rarely use (but probably should) is deep chaining. What I mean about deep chaining is using the find() function, paired with end(). I personally prefer just calling the functions separately on the specific jQuery objects. Regardless, jQE also made use of detailing out when and how this should be used and in what context (especially helpful for callbacks and special functions). While re-reading over the selectors chapters, I can't help but think to my self "A lot of this would be easier in 1.4 with the new functions, has() and not().", but you can still create your own selection filters (which is awesome).
// Define custom filter by extending $.expr[':']
$.expr[':'].positionAbsolute = function(element) {
return $(element).css('position') === 'absolute';
};
var divs = $('div:positionAbsolute');
I always forget that you can create your own selection filters (just a reminder to myself!). Back on topic, jQE gets more in depth and accompanies it with more examples, so a must read if you are interested in such techniques. I bet you didn't know that you can nest filters as well:
var divs = $('div:not(:has(.jQuery))');
var ps = $('p').filter(':not(:first):not(:last)');
Moving on, the chapters on traversal are really well done, as it talks about rarely used functions like andSelf() and contents() (to me at least). However, I really feel like the forms chapter could of been a bit more in depth. It described how to properly select radios, checkboxes, selects, etc, but I felt as if something was missing. I noticed that when talking about getting/setting values for selects, that jQE might be wrong or out of date, as I am able to set the value of a select by passing the "value" tag of the option, and not the text. Maybe this has been updated in newer versions of jQuery, or I'm just blind. Besides that little mishap, it provides some great examples on how to select certain options based on the selection filters (pretty nifty!).
$('#select option:not(':selected')');
When talking about events and binds, it was pretty straight forward. Events in itself aren't that complicated to understand, especially in jQuery. However, there was one minor feature I didn't know about, and that was passing an empty bind function will trigger the previous bind.
// Alert will automatically trigger since we are passing an empty click()
$('a').click(function(){ alert('Its black magic!') }).click();
Actually, I just got a bit ahead of myself. There are some pretty exciting things you can do with events, like event specific namespacing, and using the event object functions (preventDefault(), stopPropagation(), etc). I won't get into this subject, as you should purchase jQE and find it out for yourself! Oh, did you also know that you can disable the right click menu in your browser (not in Opera, sorry guys!), by simply using jQuery? Me neither!
$(document).bind('contextmenu', function() {
return false;
});
Now for the bigger topics, Plugins, Effects amd AJAX. jQE covers the basics on how to properly write and create a basic skeleton for your plugins. It goes over the correct usage and context for this, how to apply the plugin to all selected elements with the each command, how to return and chain properly and how to easily extend and creating custom settings. Now that's basically all it talks about, which I think was too short. I've seen so many different variations and usages for jQuery plugins, and so many of them wrote it differently. For example, Ive seen people define functions within the each() loop, as well as outside the loop scope. I'm assuming this sets the visibility to private so that the functions can not be called, but what if I do want to call a plugin function?
$.fn.myPlugin.someFunction = function() {
// Do something
}
Is it possible for me to call this function outside of the plugin, or does a plugin only package everything and do it automatically. There was too many "What if", "How does" type questions I was thinking to myself, and jQE was unable to answer. But these type of questions are probably best asked in larger more in depth books.
I don't want to keep boring you with minor details, and I would like to leave the chapters on AJAX and Effects alone (aka the exciting ones). By doing so, I hope you go purchase this document and read it for yourself. I promise you won't be disappointed.
Besides a few minor gripes and unanswered questions, jQE delivered everything I needed to know on how to properly use jQuery. It did its best to go into detail, and to also describe how the internals are working. I personally liked the fact that the document was littered with multiple examples on how to optimize and write fast code. A quick example for your enjoyment (and you may have not known that you can pass objects as an argument!).
$('a').css({'display': 'block', 'color': 'red'}).attr({'title': 'Title Txt', 'href': 'http://www.jquery.com'});
All in all, this was a great book to start learning jQuery. However, there was one thing I completely disliked, and it was when the book prefixed variables with a $ ($var), ugh! Sorry, this is Javascript, not PHP!
In closing, be prepared for my next review on AJAX and PHP: Building Modern Web Applications 2nd Edition, as I know some of my readers will enjoy it (yes you!).