Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Image

jQuery in Action 154

Michael J. Ross writes "As perhaps the only substantial computer language embedded inside of the major Web browsers, JavaScript has brought an unprecedented level of power to client-side programming for the Internet. Yet as a result of cross-browser incompatibilities and other problems, it has probably also resulted in an unprecedented number of headaches for Web developers. JavaScript libraries attempt to mitigate much of these difficulties. One of the most popular such libraries, jQuery, is explored in a book by Bear Bibeault and Yehuda Katz, titled jQuery in Action." Keep reading for the rest of Michael's review.
jQuery in Action
author Bear Bibeault and Yehuda Katz
pages 376
publisher Manning Publications
rating 9/10
reviewer Michael J. Ross
ISBN 978-1933988351
summary A well-crafted guide to jQuery.
Released by Manning Publications on 7 February 2008, under the ISBNs 1933988355 and 978-1933988351, jQuery in Action attempts to cover a large amount of information within its 376 pages. The material is grouped into nine chapters: an introduction to jQuery; wrapped element sets; modifying element properties, attributes, styling, and content; browser event models, including jQuery's; animations and effects; jQuery utility functions; plug-ins; AJAX; and four powerful plug-ins. The book concludes with an appendix, which may be the best place to start reading in the book, because it reviews many of the key aspects of JavaScript upon which more advanced jQuery heavily relies. The authors assume that the reader has a solid understanding of JavaScript, and is familiar with the basics of AJAX

As an introduction to jQuery, the first chapter briefly presents the rationale behind jQuery and its contribution to "Unobtrusive JavaScript," which is essentially the long overdue separation of JavaScript and CSS code from HTML markup — that is to say, separating behavior from structure in Web pages. With this new approach to JavaScript, the resultant code may in some cases be a bit longer, but it is far more readable, maintainable, and robust. Anyone who has tried to decipher cryptic JavaScript interwoven with HTML, will appreciate this leap forward. However, after these first two sections, prior to starting with the details of jQuery and its syntax, the authors should have explained to the reader where to find jQuery and how to reference it within a page. This critical information is provided only in the chapter summary, almost as an afterthought. A reader skipping the chapter summary could easily miss it.

The second and third chapters lay the groundwork for what will follow. The former chapter explains how to specify and manipulate sets of elements on the Web page, known as "wrapped element sets." This is done using all of the selection methods supported by CSS 3, as well as some additional selection capabilities built into jQuery. The latter chapter explains how to manage the properties and attributes of page elements, and how to get and set attribute values and other attribute manipulation techniques. The authors show how jQuery gives programmers tremendous control over the HTML and CSS of their Web pages, which can be changed by creating and modifying elements, and wrapping them in new elements, as well as adding and removing class names within the HTML, thereby using the existing CSS code. On the other side of the same coin, styling can also be updated by getting and setting the styles themselves, thereby using the existing HTML code. The last section of the third chapter focuses on form elements, which have special properties within both HTML and jQuery.

Event handling is a key aspect of any GUI, and is the subject of Chapter 4, in which the authors describe the DOM event models — focusing on Levels 0 and 2 — and how the jQuery event model helps to neutralize the problems introduced by Internet Explorer (naturally) failing to follow industry standards in its implementation of the DOM Level 2 Event Model. The chapter concludes with an extended examination of some sample code — in this case an order page from the online menu of an imaginary Asian fusion restaurant.

The book shifts gears in its fifth chapter, which explains how to use animation and other effects to jazz up the Web page — such as fading images in and out, as well as smoothly resizing and moving elements on the page. For instance, the first application of these capabilities is in the form of a collapsible list, which is ideal for making lengthy vertical navigation menus far less space consuming. Chapter 6 arms the reader with an understanding of jQuery's many utility functions, which can be used to trim unneeded spaces from strings, iterate through collections and properties, filter and translate arrays, extend objects, load scripts dynamically, and determine the site visitor's user agent and box model. These functions add the capabilities to one's jQuery code; yet one can even extend jQuery itself, by using plug-ins created by other developers or by oneself. In Chapter 7, the authors explain how anyone can write custom utility functions, which they illustrate with a date formatting function. They also explain how-to create custom wrapper methods.

Although it has its detractors, Asynchronous JavaScript and XML (AJAX) has enabled a plethora of new ways to make Web pages respond faster to user events, without requiring the overhead of wholesale page reloads. AJAX is the topic of Chapter 8, and the authors begin with a review of how to make asynchronous requests using the JavaScript XHR object, thus enabling the page to communicate with the server. This can be used for loading content into page elements, making GET and POST requests, and more. Similar to the previous two chapters, this one ends with a detailed examination of sample code. The final chapter in the book begins with a brief overview of jQuery plug-ins, and then examines in detail four highly popular plug-ins for handling HTML forms, controlling the dimensions of elements, declaring element behavior prior to creating the elements themselves, and gaining even greater control over the user interface, such as dragging and dropping elements on the page.

Anyone interested in learning more about the book can consult the publisher's page, which offers a book description, excerpts from reviews, and links to pages containing the supplemental sections of the book, such as the table of contents. It also has the book's errata, of which there are listed (as of this writing) five in the second printing, and three from the previous printing. Two sample chapters (2 and 5) are offered, as well as all of the sample source code. The PDF version of the book can be purchased online, at a discount to the printed version; the two can also be purchased as a bundle. Lastly, there is an authors' forum, where readers are invited to post questions, almost all of which have been kindly answered why the authors.

jQuery in Action illustrates how the primary aim of programming frameworks is to encapsulate much of the details of the language being used, so the developer can focus on the higher-level purpose of the code they are creating, and not the minutia of syntax and, in the case of JavaScript, differences among browsers. The authors successfully demonstrate the major concepts, primarily through the use of what they refer to as "lab pages" — essentially detailed code samples, with explanations, beginning with the second chapter. These exemplify the spirit of Manning's "in Action" series of technical books, which recognizes that in computer programming — as with probably most every other field — the best way to learn is by doing, and in this case, seeing sample code in action. This also makes it easier for the reader to modify the given code and experiment with it, to confirm what they have learned, and perhaps discover something new. Most of the sample code for this book runs fine in a Web browser opening the HTML files, without having to be run on a local Web server.

This book should prove a favorite among jQuery developers. The authors zero in on the core components of the library, and explain everything clearly — providing thorough coverage, without excessive verbiage. They are forthright about the weaknesses of jQuery, just as much as its strengths. The book does not contain a large number of screenshots or other figures, but it does use those in conjunction with code snippets, tables, and command syntax summaries to help break up the text visually. The authors improve the readability of the material with a genuine sense of humor, yet without resorting to the silliness currently found in many books written by programmers.

There are few blemishes, and of those, none are major. Phrasing in a few instances could be confusing to the average reader, such as referring to functions as elements just a few paragraphs after mentioning CSS elements (in the "NOTE" on page 9). The chapter summaries add no value, and should be jettisoned. Also, they should not be used as a place to introduce information not even mentioned in the corresponding chapters, e.g., the jQuery download information noted above. Almost every chapter summary touched upon something that had not proceeded it; such material should be folded into the particular chapter proper. The chapter titles should be in title case, and not sentence case. On the other hand, some phrases are incorrectly put in title case, such as "Rich Internet Applications" — a phrase overused. There were only a few errata not already reported on the publisher's Web page, such as "it incursion" (page 15). As with many computer books nowadays, there is an excessive use of exclamation marks. In terms of the sample code, it is complete and quite handy for trying out the ideas discussed in the book, and learning by modifying it. However, the JavaScript portions of the code can be difficult to read, because most of the code is compressed, with almost no use of whitespace to enhance readability.

With its capable technical coverage, extensive use of sample code, and approachable style, jQuery in Action is a valuable resource for any Web developer seeking to maximize the power of JavaScript, and a must-have for anyone interested in learning jQuery.

Michael J. Ross is a Web developer, writer, and freelance editor.

You can purchase jQuery in Action from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

*

This discussion has been archived. No new comments can be posted.

jQuery in Action

Comments Filter:
  • GWT FTW (Score:4, Informative)

    by darkvad0r ( 1331303 ) on Wednesday November 26, 2008 @01:58PM (#25901397)

    as a result of cross-browser incompatibilities and other problems, it has probably also resulted in an unprecedented number of headaches for Web developers. JavaScript libraries attempt to mitigate much of these difficulties.

    IMHO GWT is the closest one to that goal. If you're a Java developer give it a go, if you're not, then GWT is the perfect reason to become one :)

  • Re:Vs. Mootools? (Score:4, Informative)

    by xmuskrat ( 613243 ) on Wednesday November 26, 2008 @02:24PM (#25901647) Homepage
    I might use ext for an intranet project, but it seems to be a big pain on doing things the way I want to put them together. It's annoying to have so much formatting in JSON where if you miss a comma somewhere, the page doesn't even render let alone handle the error. I think the core of a good JS library is a great, fast CSS selector model and extensive plugin support. JQuery helps me write clean, easily readable code that almost always is reusable in a different situation.
  • Re:Vs. Mootools? (Score:5, Informative)

    by rgigger ( 637061 ) on Wednesday November 26, 2008 @02:25PM (#25901661)

    That was my feeling too until I learned about how he licenses the code, and his views on what the GPL3 means for web applications.

    http://extjs.com/products/license.php [extjs.com]

    If you are writing an open source app then that's great but if you are going to use it at your company for a closed source project make sure they understand they need to buy a commercial license from the author.

  • Re:A simple request (Score:3, Informative)

    by gandhi_2 ( 1108023 ) on Wednesday November 26, 2008 @02:29PM (#25901689) Homepage
    The jQuery authors tell you to design your code to "fail gracefully". Let the content still be accessible even if the stylesheet is missing or the js doesn't run.
  • Re:A simple request (Score:5, Informative)

    by vux984 ( 928602 ) on Wednesday November 26, 2008 @02:30PM (#25901695)

    Don't use scripting to sanitize your POST submissions; You should handle that on the backend, it's more secure anyway.

    You ALWAYS should handle it on the backend regardless, but doing it on the front-end TOO isn't necessarily a bad idea; it takes some load off the backend, and saves the user waiting for a round-trip to the server to find out something simple is missing or whatever.

  • Re:A simple request (Score:2, Informative)

    by Anonymous Coward on Wednesday November 26, 2008 @03:26PM (#25902211)

    they should still be able to submit a POST query and get useful results back.

    I'm a bit confused by this. You do realize it's entirely possible to have client-side error checking on a form AND have it still submit to the server(for server-side error checking) if javascript is disabled, right?

    What you are describing is a problem with people designing bad client-side checking, not a problem inherent to client-side checking itself.

  • Re:Vs. Mootools? (Score:3, Informative)

    by naoursla ( 99850 ) on Wednesday November 26, 2008 @03:52PM (#25902455) Homepage Journal

    ext is much larger than jquery. It takes longer to initialize the runtime environment. That may or may not be an issue depending on the application you are writing.

  • Re:Vs. Mootools? (Score:3, Informative)

    by Mr. DOS ( 1276020 ) on Wednesday November 26, 2008 @04:10PM (#25902643)

    Amazingly. Not only is jQuery thoroughly documented, demos and examples are widely available. Also, the amount of code required to do something is drastically smaller (and therefore, faster to write) for simple stuff, without restricting your options when you want to do something more complex.
    $.get('test.php', function(data) {
            $('#div').html(data);
    });

    That (if I got it right off the top of my head) makes a GET request to the file test.php and dumps whatever test.php produced into an element with the ID "div".

    You specifically mentioned Mootools. I used it (and liked it) for a while, but I eventually got frustrated with the lack of documentation and the amount of JavaScript it took to get anything done. I really encourage you to take a shot at jQuery just to see how it matches up.

    One thing that did take me a while to get used to is the non-Prototype-like selectors: if you're selecting an ID, you can't just do $('el'); you've got to do $('#el'). However, this really simplifies things if you've got to select by class ( $('.class') ).

          --- Mr. DOS

  • Re:Vs. Mootools? (Score:2, Informative)

    by drpimp ( 900837 ) on Wednesday November 26, 2008 @05:56PM (#25903747) Journal
    I recently just added the intellisense for my ASP.NET MVC project I am working on. My only question is the some what (IMHO) hackish way to have to include a vsdoc.js file in the project, or adding some if(false) {} ASP logic to get the intellisense to work thinking it included the javascript file for view pages if your actual jquery javascript src is in the site.master. Not to mention if you have prototype used in your project as well it will not work as expected. You end up not being able to use the shortcut $() nor if you make a noConflict alias $j(). But if you do something like $j = jQuery; then it will start to work again. Oh and you must be using the NON-minified version to get any sort of details of the parameters. I know it's minified and that the reason why, but if anyone else has that problem just thought I'd point that out.
  • Re:Vs. Mootools? (Score:4, Informative)

    by grahamd0 ( 1129971 ) on Wednesday November 26, 2008 @07:25PM (#25904625)

    If you're into grokking the underlying language, try reading John Resig's book [jspro.org] or his articles online [ejohn.org].

    I've found that my desire to have a fundamental understanding of javascript, which kept me away from most of the popular libraries for quite a while, is one of the main reasons I love jQuery, and also that understanding jQuery and how it works has given me a much better fundamental understanding of javascript.

    While jQuery does create a pretty big abstraction from the core DOM functions, it does so efficiently.

    I'm confident that when I use jQuery to find a list of elements with a particular class for example, that I wouldn't be able to write something from scratch to achieve the same effect that would be substantially more resource efficient.

    It's also, last I looked, the smallest download of any of the major js libraries.

  • Re:Vs. Mootools? (Score:3, Informative)

    by grahamd0 ( 1129971 ) on Wednesday November 26, 2008 @09:35PM (#25905427)

    I suppose it would more accurate to say learning how jQuery works has helped be better understand javascript, rather than simply using it.

    The best example that comes to mind is the way that jQuery handles queuing functions to fire when the document is ready. I don't recall the specifics off the top of my head, but reading Resig's articles on that and other topics have really given me a better handle on the core concepts of javascript.

  • Re:Vs. Mootools? (Score:4, Informative)

    by apathy maybe ( 922212 ) on Thursday November 27, 2008 @03:24AM (#25906879) Homepage Journal

    I can't see anything on their webpage that indicates that they have a strange interpretation of the GPL v3.

    I get the impression that they believe merely using ext JS on a public website is distribution. I would agree with that. Therefore, if you modify the code, and then distribute it, you have to release under GPL v3 to be "legal". I don't see anything wrong with that.

    You don't have to modify the code, and therefore, you don't have any obligations.

    In either case, you don't have to worry about the source code requirement, because the source code is being downloaded by the browser anyway.

    Regarding server side code, that's different. You aren't distributing the code, you are merely presenting the results of the code. I understand that in the USA and Australia at least, that it is not possible to copy right the output of a program (at least not in general cases).

    So, you can take WordPress (which is released under the GPL), and modify it all you want, and so long as your modifications stay on your server, you have no worries.

    This "hole" in the GPL coverage is "closed" by the AGPL, which mandates that if you modify the code, and use it, then you have to offer a link to download the changed source code to anyone who accesses the program over a network. (Or something like that anyway, see section 13.)

    The question of which is more appropriate, depends on who you consider the "user" to be, the public, or the web master.

There are two ways to write error-free programs; only the third one works.

Working...