Oct 07

Book review: jQuery Succinctly



  1. Introduction
    For developers, there is a need to keep up to date with the latest technologies, in a rapidly changing landscape. While the internet does allow for easier access to information resources, the truth is that there is probably nothing like a good book to provide a structured approach to a given technology. With a book, readers can benefit from the author’s experience and knowledge right from the beginning, and can be given a guided tour that makes learning probably a lot easier than going through a series of website articles.

    Recently I became aware of a series of free books made available by Syncfusion. I am sucker for books, so I downloaded a few, relevant to some of the technologies I use, to check them. One of those books is the subject of this review – jQuery Succinctly. The book author is Cody Lindley, described in the book as having been a jQuery evangelist with the jQuery team.

    jQuery is one of the technologies that powers the Web, these days. In most websites with a great user experience, most certainly jQuery is used to provide such experience. So my goal on reviewing this book is to evaluate it as a useful resource for someone wanting to how to use it for website development.

  2. Book Structure

    The book is organized in 10 chapters, starting with Core jQuery and including chapters such as Selecting, Traversing, Manipulation, HTML Forms, Events, jQuery and the web browser, Plugins, Effects and Ajax. This seems a decent coverage of the subjects related to jQuery to allow any developer to use it effectively for website development. The presentation is supported by examples, that are usually well chosen and helpful. The code can be downloaded, making it easier to follow the examples as the reading proceeds.

     Chapter 1, Core jQuery, introduces the reader to the core concepts of jQuery – in the words of the author, “find something, do something”, that is then extended to “create something, select it and do something with it”. This chapter also deals with other relevant introductory aspects like dealing with the wait for the DOM to be parsed or waiting for the full window to load, jQuery chaining, jQuery methods that break the chain and how recovery from such destruction can be achieved using end(). It also introduces the this keyword, iterating over multiple selected elements using .each(), accessing selected elements by index using get() and creating DOM elements. The chapter provides a decent introduction to all these subjects, even if in a rather brief way. 

    Chapter 2, Selecting is devoted to DOM elements selection. It starts with a presentation of filters or, as some other authors name them, jQuery type extension selectors. The is() method, to determine if a given element is present in the selected set of elements and the length property, are presented. The chapter also shows how custom selectors (filters) can be created, when jQuery does not provide the selectors you may need. A decent presentation of selectors that explore relationships between elements follows, as well as selector stacking and nesting. I found the chapter quite interesting and it did cover some selection techniques I hadn’t found in other jQuery books I read before.

    Traversing is the 3rd book chapter, dedicated to DOM traversing. Strangely it starts with the filter() and find() methods, which probably would make more sense in the previous chapter. The coverage is succinctly good. The DOM traversing methods parent(), parents(), closest() are introduced and differences explained. Other traversing methods are also briefly addressed.

    Chapter 4, Manipulation, addresses the creation, operation and addition of HTML, using jQuery. HTML creation is exemplified as is the addition of such HTML to the DOM using appendTo(). The Index() method and why you’d use it is also presented. The use of text() and other methods such as replace(), contents() or remove() are exemplified.

    Chapter 5, HTML Forms, presents jQuery features to handle HTML forms. The attr() and removeAttr() methods to change or disable form elements, as well as the use of filter attributes such as :enabled and :disabled. Radio and checkbox selection and checking is exemplified, using val() and filter attributes such as :checked or :hidden. Use of val() to set the value of input elements and <textarea> is presented. Multiple examples are given of common tasks of elements edition, using methods such as prepend(), html() or replacewith(). Form elements selection by type is demonstrated through examples. Overall, the chapter is a good read but, similar to what I found regarding Ajax as a general subject, it is a shame that Ajax form submission is not covered.

    Chapter 6 deals with Events. Dealing with events is one of the most important features of jQuery and the chapter covers the subject nicely. It starts with an explanation about how there can be multiple ready() events declared. It then addresses the use of bind() and unbind() with multiple handlers. It also shows how event handlers can be invoked through short methods and addresses the event normalization performed by jQuery, showing how access to the normalized event can be achieved. Event namespacing advantages, and how namespacing can be achieved, are presented. Event delegation is introduced and its advantages are highlighted. The use of live() to bind event handlers that will be applied even to DOM elements created after the binding is perform is also shown and the methods specificities are explained. Preventing the browser from taking default behaviors or stopping event propagation, using stopPropagation or using return false, when opening a link or submitting a form is also addressed. The creation of custom events using bind and their invocation using trigger is also presented, as is cloning events using clone. I found this to be a very interesting chapter, addressing most situations a developer may need regarding event handling.

    Chapter 7, jQuery and the browser, is a bit of a weird one. It covers two small subjects only – disabling the right click button and scrolling the browser window. In its succinctness, it’s pretty similar to chapter 10 and I confess I fail to see the point of having a chapter with such small amount of content.

    Chapter 8 addresses Plugins. It starts with the recommendation to use the $ alias only within a private scope to avoid conflicts and the way to do that is demonstrated. The use of $.fn to make plugin methods chainable, just as jQuery native methods, is explained and exemplified. Default and custom plugin options are presented. Programmatic invocation of plugins is addressed. Although useful and addressing relevant contents related to the subject, a reference to utility functions could have been made, even if succinctly.

    Chapter 9 deals with Effects. This chapter starts in a bit of a weird manner. The first statement is that all jQuery animation effects can be disabled by setting the value of the off property to true. If you consider that the book may be read by someone who never used jQuery’s animation effects, this introduction may actually lack some context. The text proceeds in the same tone by stating that the stop() method should be used to stop an ongoing animation, before starting a new one. The rest of the chapter discusses the use of show(), hide() and toggle() without animation. Exemplifies sequential and non sequential animations, using animate(). Presents it as a base abstraction and offers detailed suggestions on how it can be used. The chapter also presents jQuery’s fading methods, fadeIn(), fadeout() and fadeTo()

    Chapter 10, Ajax, address jQuery Ajax related features. I found this chapter a bit disappointing. It basically presents the $.ajax() function as the low level abstraction by the shortcut methods load(), get(), getJSON(), getScript(), and post(), but without actually providing examples of their use. There is another additional paragraph stating that jQuery supports cross-domain JSONP and shows how browser XHR requests caching can be disabled – this is a piece of actually useful info, much to the contrary of the rest of the chapter.

  3. Conclusion

    The author states, in the book introduction, that the book was written to express the concepts essential to intermediate and advanced jQuery development, with each chapter containing concepts essential to becoming a jQuery developer. I confess I didn’t really look at it under this perspective. Although maybe a bit unfairly, I suspect, considering Syncfusion’s audience, that it will be used, at least in a relevant part, by developers fluent in Microsoft’s web technologies, to become familiar with jQuery, to use it in the development of websites. So, from a web developer’s point of view, I found the book rather useful, with some very good chapters (2, 5 and 6 are my favorites) and others not as good (especially 7 and 10). Even if some chapters could benefit from a bit better coverage of the underlying subjects or a better organization, the book can be a valuable resource. All the subjects are dealt with in a succinct manner, which is the purpose of the Syncfusion ebook series, anyway, which means it cannot probably be the single book to have on jQuery, but it does provide some valuable information and you can’t beat the cost. It is also a book that you can keep nearby, to be used as a reference. I will keep my copy within easy reach.