Tutorials
jQueryby Jonathan Chaffer and Karl Swedberg A Comprehensive Exploration of the Popular JavaScript Library
jQuery
Reference Guide
http://www.packtpub.com/jquery-reference-guide-Open-Source/book
Anatomy of a jQuery Script
He's got a brand new start
Now he's a happy guy
—Devo,
"Happy Guy"
A typical jQuery script uses a wide assortment of the methods that the library offers. Selectors, DOM manipulation, event handling, and so forth come into play as required by the task at hand. In order to make the best use of jQuery, we need to keep in mind the wide range of capabilities it provides.
This book will itemize every method and function found in the jQuery library. Since there are many methods and functions to sort through, it will be useful to know what the basic categories of methods are, and how they come into play within a jQuery script. Here we will see a fully functioning script, and examine how the different aspects of jQuery are utilized in each part of the script.
Thanks to Duane Moraes @ Packt Publishing for giving opportunity to provide sample chapter for Exforsys members.
As an example of jQuery in action, we'll build a small script that will dynamically extract the headings from an HTML document and assemble them into a table of contents for that page.
Sponsored Links
Our table of contents will be nestled on the top right corner of the page:

We'll have it collapsed initially as shown above, but a click will expand it to full height:

At the same time, we'll add a feature to the main body text. The introduction of the text on the page will not be initially loaded, but when the user clicks on the word Introduction, the introductory text will be inserted in place from another file:

Before we reveal the script that performs these tasks, we should walk through the environment in which the script resides.
The official jQuery website (http://jquery.com/) is always the most up-to-date resource for code and news related to the library. To get started, we need a copy of jQuery, which can be downloaded right from the home page of the site. Several versions of jQuery may be available at any given moment; the latest uncompressed version will be most appropriate for us.
No installation is required for jQuery. To use jQuery, we just need to place it on our site in a public location. Since JavaScript is an interpreted language, there is no compilation or build phase to worry about. Whenever we need a page to have jQuery available, we will simply refer to the file's location from the HTML document.
There are three sections to most examples of jQuery usage— the HTML document itself, CSS fi les to style it, and JavaScript fi les to act on it. For this example, we'll use a page containing the text of a book:
NOTE: The actual layout of files on the server does not matter. References from one file to another just need to be adjusted to match the organization we choose. In most examples in this book, we will use relative paths to reference files (../images/foo.png) rather than absolute paths (/images/foo.png). This will allow the code to run locally without the need for a web server.
The stylesheet is loaded immediately after the standard <head> elements. Here are the portions of the stylesheet that affect our dynamic elements:
Sponsored Links
Next Page: Writing the jQuery Code