Book Image

Learning jQuery 1.3

By : Jonathan Chaffer, Karl Swedberg
Book Image

Learning jQuery 1.3

By: Jonathan Chaffer, Karl Swedberg

Overview of this book

<p>To build interesting, interactive sites, developers are turning to JavaScript libraries such as jQuery to automate common tasks and simplify complicated ones. Because many web developers have more experience with HTML and CSS than with JavaScript, the library's design lends itself to a quick start for designers with little programming experience. Experienced programmers will also be aided by its conceptual consistency. <br /><br />Revised and updated for version 1.3 of jQuery, this book teaches you the basics of jQuery for adding interactions and animations to your pages. Even if previous attempts at writing JavaScript have left you baffled, this book will guide you past the pitfalls associated with AJAX, events, effects, and advanced JavaScript language features.<br /><br />In this book, the authors share their knowledge, experience, and enthusiasm about jQuery to help you get the most from the library and to make your web applications shine. The book introduces jQuery and shows how you can write a functioning jQuery program in just three lines of code. It then guides you through CSS selectors and shows how to enhance the basic event handling mechanisms to give them a more elegant syntax. You will then learn to add impact to your actions through a set of simple visual effects and also to create, copy, reassemble, and embellish content using jQuery's DOM modification methods. You will also learn to send and retrieve information with AJAX methods. The book will then step you through many detailed, real-world examples and even equip you to extend the jQuery library itself with your own plug-ins.</p>
Table of Contents (22 chapters)
Learning jQuery 1.3
Credits
Foreword
About the Authors
About the Reviewers
Preface
Index

Preface

It began as a labor of love back in 2005 by John Resig, a JavaScript wunderkind who now works for the Mozilla Corporation. Inspired by pioneers in the field such as Dean Edwards and Simon Willison, Resig put together a set of functions to make it easy to programmatically find elements on a web page and assign behaviors to them. By the time he first publicly announced his project in January 2006, he had added DOM modification and basic animations. He gave it the name jQuery to emphasize the central role of finding, or "querying," parts of a web page and acting on them with JavaScript. In the few short years since then, jQuery has grown in its feature set, improved in its performance, and gained widespread adoption by some of the most popular sites on the Internet. While Resig remains the lead developer of the project, jQuery has blossomed, in true open-source fashion, to the point where it now boasts a core team of top-notch JavaScript developers, as well as a vibrant community of thousands of developers.

The jQuery JavaScript Library can enhance your websites regardless of your background. It provides a wide range of features, an easy-to-learn syntax, and robust cross-platform compatibility in a single compact file. What's more, hundreds of plug-ins have been developed to extend jQuery's functionality, making it an essential tool for nearly every client-side scripting occasion.

Learning jQuery provides a gentle introduction to jQuery concepts, allowing you to add interactions and animations to your pages—even if previous attempts at writing JavaScript have left you baffled. This book guides you past the pitfalls associated with AJAX, events, effects, and advanced JavaScript language features, and provides you with a brief reference to the jQuery library to return to again and again.

What this book covers

In Chapter 1 you'll get your feet wet with the jQuery JavaScript library. The chapter begins with a description of jQuery and what it can do for you. It walks you through downloading and setting up the library, as well as writing your first script.

In Chapter 2 you'll learn how to use jQuery's selector expressions and DOM traversal methods to find elements on the page, wherever they may be. You'll use jQuery to apply styling to a diverse set of page elements, sometimes in a way that pure CSS cannot.

In Chapter 3 you'll use jQuery's event-handling mechanism to fire off behaviors when browser events occur. You'll see how jQuery makes it easy to attach events to elements unobtrusively, even before the page finishes loading. And, you'll be introduced to more advanced topics, such as event bubbling, delegation, and namespacing.

In Chapter 4 you'll be introduced to jQuery's animation techniques and see how to hide, show, and move page elements with effects that are both useful and pleasing to the eye.

In Chapter 5 you'll learn how to change your page on command. This chapter will teach you how to alter the very structure of an HTML document, as well as its content, on the fly.

In Chapter 6 you'll discover the many ways in which jQuery makes it easy to access server-side functionality without resorting to clunky page refreshes.

In the next three chapters (7, 8, and 9) you'll work through several real-world examples, pulling together what you've learned in previous chapters and creating robust jQuery solutions to common problems.

In Chapter 7, "Table Manipulation," you'll sort, sift, and style information to create beautiful and functional data layouts.

In Chapter 8, "Forms with Function," you'll master the finer points of client-side validation, design an adaptive form layout, and implement interactive client-server form features such as autocompletion.

In Chapter 9, "Shufflers and Rotators," you'll enhance the beauty and utility of page elements by showing them in more manageable chunks. You'll make information fly in and out of view both on its own and under user control.

Chapters 10 and 11 take you beyond the core jQuery methods to explore third-party extensions to the library, and show you various ways you can extend the library yourself.

In Chapter 10, "Using Plug-ins," you'll examine the Form plug-in and the official collection of user interface plug-ins known as jQuery UI. You'll also learn where to find many other popular jQuery plug-ins and see what they can do for you.

In Chapter 11, "Developing Plug-ins," you'll learn how to take advantage of jQuery's impressive extension capabilities to develop your own plug-ins from the ground up. You'll create your own utility functions, add jQuery object methods, write custom selector expressions, and more.

In Appendix A, "Online Resources," you'll find recommendations for a handful of informative websites on a wide range of topics related to jQuery, JavaScript, and web development in general.

In Appendix B, "Development Tools," you'll discover a number of useful third-party programs and utilities for editing and debugging jQuery code within your personal development environment.

In Appendix C, "JavaScript Closures," you'll gain a solid understanding of closures—what they are and how you can use them to your advantage.

In Appendix D , "Quick Reference," you'll get a glimpse of the entire jQuery library, including every one of its methods and selector expressions. Its easy-to-scan format is perfect for those moments when you know what you want to do, but you're just unsure about the right method name or selector.

What you need for this book

In order to both write and run the code demonstrated in this book, you need the following:

  • A basic text editor.

  • A modern web browser such as Mozilla Firefox, Apple Safari, or Microsoft Internet Explorer.

  • The jQuery source file, version 1.3.1 or later, which can be downloaded from http://jquery.com/.

Additionally, to run the AJAX examples in Chapter 6, you will need a PHP-enabled server.

Who is this book for

This book is for web designers who want to create interactive elements for their designs, and for developers who want to create the best user interface for their web applications. Basic JavaScript programming knowledge is required. You will need to know the basics of HTML and CSS, and should be comfortable with the syntax of JavaScript. No knowledge of jQuery is assumed, nor is experience with any other JavaScript libraries required.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code will be set as follows:

<html>
  <head>
    <title>the title</title>
  </head>
  <body>
    <div>
      <p>This is a paragraph.</p>
      <p>This is another paragraph.</p>
      <p>This is yet another paragraph.</p>
    </div>
  </body>
</html>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be made bold:

$(document).ready(function() {
  $('a[href^=mailto:]').addClass('mailto');
  $('a[href$=.pdf]').addClass('pdflink');
  $('a[href^=http][href*=henry]')
    .addClass('henrylink');
});

Any command-line input and output is written as follows:

outerFn():Outer functionInner function

New terms and important words are introduced in a bold-type font. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "Note the PDF icon to the right of the Hamlet link, the envelope icon next to the email link, and the white background and black border around the Henry V link.".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book, what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to , making sure to mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/6705_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing this you can save other readers from frustration, and help to improve subsequent versions of this book. If you find any errata, report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to the list of existing errata. The existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide the location address or website name immediately so we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with some aspect of the book, and we will do our best to address it.