Table of Contents

Cover

Title Page

Copyright

About the Author

Credits

Introduction

Who This Book Is For

What This Book Covers

How This Book Is Structured

What You Need to Use This Book

Conventions

Source Code

Errata

p2p.wrox.com

Part I: IP/MPLS VPN Service Network Overview

Chapter 1: Introduction to jQuery

What Does jQuery Do for Me?

Who Develops jQuery?

Obtaining jQuery

Installing jQuery

Programming Conventions

Summary

Chapter 2: Selecting and Filtering

The Origin of the Selectors API

Using the Selectors API

Filtering a Selection

Summary

Exercises

Chapter 3: Events

Assigning an Event with the Traditional Event Model

Assigning Events with the W3C Event Model

The Microsoft JScript Event Model

Creating a Universal Event API

Summary

Exercises

Chapter 4: Manipulating Content and Attributes

Setting and Accessing Attributes

Manipulating Class Names

Manipulating HTML and Text Content

Replacing Elements

Removing Content

Cloning Content

Summary

Exercises

Chapter 5: Arrays and Iteration

Basic Iteration

Filtering Selections and Arrays

Mapping a Selection or an Array

Array Utility Methods

Summary

Exercises

Chapter 6: CSS

The css() Method

The outerWidth() and outerHeight() Methods

Summary

Exercises

Chapter 7: AJAX

Making a Server Request

Loading HTML Snippets from the Server

Dynamically Loading JavaScript

AJAX Events

Making an AJAX-Style File Upload

Summary

Exercises

Chapter 8: Effects

Showing and Hiding Elements

Sliding Elements

Fading Elements

Custom Animation

Summary

Exercises

Chapter 9: Plugins

Writing a Plugin

Good Practice for jQuery Plugin Development

Summary

Exercises

Part II: jQuery UI

Chapter 10: Implementing Drag-and-Drop

Making Elements Draggable

Making Elements Draggable with Ghosting

Dragging between Windows in Safari

Delegating Drop Zones for Dragged Elements

Summary

Exercises

Chapter 11: Drag-and-Drop Sorting

Making a List Sortable

Customizing Sortables

Saving the State of Sorted Lists

Summary

Exercises

Chapter 12: Selection by Drawing a Box

Introducing the Selectables Plugin

Summary

Exercises

Chapter 13: Accordion UI

Building an Accordion UI

Setting Auto-Height

Changing the Default Pane

Toggling the alwaysOpen Option

Changing the Accordion Event

Filling the Height of the Parent Element

Setting the Header Elements

Styling Selected Panes

Selecting a Content Pane by Location

Summary

Exercises

Chapter 14: Datepicker

Implementing a Datepicker

Localizing the Datepicker

Summary

Exercises

Chapter 15: Dialogs

Implementing a Dialog

Examining a Dialog’s Markup

Making a Modal Dialog

Auto-Opening the Dialog

Controlling Dynamic Interaction

Animating the Dialog

Working with Dialog Events

Summary

Exercises

Chapter 16: Tabs

Implementing Tabs

Loading Remote Content via AJAX

Animating Tab Transitions

Summary

What Next?

Exercises

Appendix A: Answers to Exercises

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

Chapter 13

Chapter 14

Chapter 15

Chapter 16

Appendix B: Selectors Supported by jQuery

Appendix C: Selecting and Filtering

Appendix D: Events

Event Object Normalization

Appendix E: Manipulating Attributes and Data Caching

Appendix F: Manipulating Content

Appendix G: AJAX Methods

Appendix H: CSS

Appendix I: Utilities

Appendix J: Draggables and Droppables

Appendix K: Sortables

Appendix L: Selectables

Notes

Appendix M: Effects

Speed

Callback Function

Appendix N: Accordion

Appendix O: Datepicker

Appendix P: Dialog

Appendix Q: Tabs

Appendix R: Re-Sizables

Appendix S: Sliders

Index

Advertisement

Beginning JavaScript® and CSS Development with jQuery

Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com

Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-22779-4

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

Library of Congress Cataloging-in-Publication Data

York, Richard. Beginning JavaScript and CSS development with jQuery / Richard York. p. cm. Includes index. ISBN 978-0-470-22779-4 (paper/website) 1. JavaScript (Computer program language) 2. Web sites--Design. 3. Cascading style sheets. I. Title. QA76.73.J38Y67 2009 006.7’6--dc22 2009005636

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. JavaScript is a registered trademark of Sun Microsystems, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

About the Author

Richard York is a web developer and author of three Wrox books in addition to this: Beginning CSS: Cascading Style Sheets for Web Design (Wiley, 2007), CSS Instant Results (Wiley, 2006), and Beginning CSS: Cascading Style Sheets for Web Design, 2nd ed (Wiley, 2007).

Website: www.deadmarshes.com

Credits

Senior Development Editor

Tom Dinse

Technical Editor

Sam Judson

Senior Production Editor

Debra Banninger

Copy Editor

Cate Caffrey

Editorial Manager

Mary Beth Wakefield

Production Manager

Tim Tate

Vice President and Executive Group Publisher

Richard Swadley

Vice President and Executive Publisher

Barry Pruett

Associate Publisher

Jim Minatel

Project Coordinator, Cover

Lynsey Stanford

Compositor

James D. Kramer, Happenstance Type-o-Rama

Proofreader

Nancy Carrasco

Indexer

J & J Indexing

Introduction

The jQuery JavaScript framework is a rising star in the world of web development. JavaScript frameworks in general have grown to become immensely popular in the past few years in parallel with the ever-increasing presence of JavaScript-driven, so-called Web 2.0 websites that make heavy use of technologies like AJAX and JavaScript in general for slick graphical enhancements that would be impossible or much more cumbersome to incorporate without JavaScript.

jQuery’s mission as a JavaScript library is simple — it strives to make the lives of web developers easier by patching over certain portions of cross-browser development and by making other tasks commonly needed by developers much easier. jQuery has the real, proven ability to reduce many lines of plain-vanilla JavaScript to just a few lines, and, in many cases, just a single line. jQuery strives to remove barriers to JavaScript development by removing redundancy wherever possible and normalizing cross-browser JavaScript development in key areas where browsers would otherwise differ, such as Microsoft’s Event API and the W3C Event API, and other, more remedial tasks like getting the mouse cursor’s position when an event has taken place.

jQuery is a compact, lightweight library that currently works in Microsoft’s Internet Explorer browser from version 6 on, Firefox from version 1.5 on, Safari from version 2.0.2 on, Opera from version 9 on, and Google’s new Chrome browser from version 0.2 on. Getting started with jQuery is very easy — all you have to do is include a single link of markup in your HTML or XHTML documents that includes the library. Throughout this book, I demonstrate jQuery’s API (Application Programming Interface) components in detail and show you how all the nuts and bolts of this framework come together to enable you to rapidly develop client-side applications.

I also cover the jQuery UI library, which makes redundant user-interface (UI) tasks on the client side ridiculously easy and accessible to everyday web developers who might not have much JavaScript programming expertise. Have you ever wanted to create an animated accordion effect like the one found on Apple’s Mac home page at www.apple.com/mac? With jQuery, not only can you create this effect with your own look and feel, but also it’s dead simple to boot.

Have you ever wondered how websites make virtual pop-up windows using JavaScript, HTML, and CSS? The jQuery UI library provides the ability to create these pop-up windows and includes the ability to animate transitions like fading the window on and off, or having it re-size from very small to full sized. The jQuery UI library gives you the ability to use animations and transitions using JavaScript, markup, and CSS that you may have thought previously could only have been done with Adobe’s Flash player.

The jQuery framework itself has enjoyed a great deal of mainstream exposure. It has been used by Google, Dell, Digg, NBC, CBS, Netflix, The Mozilla Foundation, and the popular WordPress and Drupal PHP frameworks.

jQuery is fast — superfast — and it has a small footprint. It’s only 15 KB, using the compressed and gzipped version.

jQuery gives you the ability to provide complex, professional, visually driven user interfaces and effects with very few lines of code. What may have taken other developers days or even weeks to accomplish can be done with jQuery in just a few hours.

Who This Book Is For

This book is for anyone interested in doing more with less code! You should have a basic understanding of JavaScript. I review some basic JavaScript programming concepts, such as the Event API, but I do not go into great detail about the JavaScript language itself. You’ll want to have at least a basic grasp of the Document Object Model, or DOM, and basic JavaScript programming syntax. Additionally, you’ll need to know your way around CSS and HTML, since knowledge of those technologies is also assumed. A complete beginner might be able to grasp what is taking place in the examples in this book but might not understand certain terminology and programming concepts that would be presented in a beginner’s JavaScript guide, so if you are a beginner and insist with pressing forward, I recommend doing so with a beginning JavaScript book on hand as well. Specifically, I recommend the following Wrox books for more help with the basics:

Beginning Web Programming with HTML, XHTML, and CSS, 2nd ed. (2008), by Jon Duckett

Beginning CSS: Cascading Style Sheets for Web Design, 2nd ed. (2007), also written by yours truly.

Beginning JavaScript, 3rd ed. (2007), by Paul Wilton and Jeremy McPeak

For further knowledge of JavaScript above and beyond what is covered in this book, I recommend Professional JavaScript for Web Developers, 2nd ed. (2009), by Nicholas C. Zakas.

What This Book Covers

This book covers the jQuery JavaScript framework and the jQuery UI JavaScript framework and demonstrates in great detail how to use the jQuery framework to get more results more quickly out of JavaScript programming. I cover each method exposed by jQuery’s API, which contains methods to make common, redundant tasks go much more quickly in less code. Some examples are methods that help you to select elements from a markup document through the DOM and methods that help you to traverse through those selections and filter them using jQuery’s fine-grained controls. This makes working with the DOM easier and more effortless. I also cover how jQuery eliminates certain cross-browser, cross-platform development headaches like the event model; not only does it eliminate these headaches, but it also makes it easier to work with events by reducing the amount of code that you need to write to attach events. It even gives you the ability to simulate events.

Later in the book, I cover how you can leverage the jQuery UI library to make graphically driven UI widgets. jQuery gives you the ability to break content up among multiple tabs in the same page. You have the ability to customize the look and feel of the tabs, and even to create a polished look and feel by providing different effects that come in when you mouse over tabs and click on them. The jQuery UI library also makes it easy to create accordion sidebars, like the one on Apple’s Mac website. These sidebars have two or more panels, and when you mouse over an item, one pane transitions to another via a smooth, seamless animation wherein the preceding pane collapses and the proceeding pane expands.

The jQuery UI library also gives you the ability to make any element draggable with the mouse; by clicking and holding and moving the mouse, you can move elements around on a page. It also makes it really easy to create drag-and-drop user interfaces. This can be used to make a dropping zone where you take elements from other parts of the page and drop them in another, as you would in your operating system’s file manager when you want to move a folder from one place to another. You can also make lists that are sortable via drag-and-drop, rearranging elements based on where you drop them. You can also have a user interface where you drag the mouse cursor to make a selection, as you would in your operating system’s file manager when you want to select more than one file. Then jQuery UI also exposes the ability to re-size elements on a page using the mouse. All of those neat things that you can do on your computer’s desktop, you can also do in a web browser with jQuery UI.

jQuery UI also provides a widget for entering a date into a field using a nice, accessible JavaScript-driven calendar that pops up when you click on an input field.

You can also make custom pop-up dialogues that are like virtual pop-up windows, except they don’t open a separate browser window — they come up using markup, CSS, and JavaScript.

Another widget that jQuery UI provides is a graphical slider bar, similar to your media player’s volume control.

As jQuery has done for JavaScript programming in general, jQuery UI strives to do for redundant graphical user interface (GUI) tasks. jQuery UI gives you the ability to make professional user-interface widgets with much less development effort.

If you’re interested in reading news about jQuery, how it’s evolving, and topics related to web development, you may be interested in reading the official jQuery blog at blog.jquery.com, or jQuery’s creator, John Resig’s blog, at www.ejohn.org.

If you are in need of help, you can participate in programming discussion at p2p.wrox.com, which you can join for free to ask programming questions in moderated forums. There are also programming forums provided by the jQuery community, which you can learn more about at http://docs.jquery.com/Discussion.

Finally, I maintain a blog and website at www.deadmarshes.com, where you can contact me directly with your thoughts about the book or read about the web development projects I’m working on.

How This Book Is Structured

This book is divided into two parts: The first half of the book covers the basic API exposed by the jQuery library, and the second half covers the jQuery UI library.

Part 1: jQuery API

Chapter 1: Introduction to jQuery — In this first chapter, I discuss a little of where jQuery came from and why it was needed. Then I walk you through downloading and creating your first jQuery-enabled JavaScript.

Chapter 2: Selecting and Filtering — This chapter introduces jQuery’s selector engine, which uses selectors like you will have used with CSS to make selections from the DOM. Then I talk about the various methods that jQuery exposes for working with a selection, to give you fine-grained control over what elements you’re working with from the DOM. I talk about methods that let you select, ancestor elements, parent elements, sibling elements, descendent elements, how to remove elements from a selection, how to add elements to a selection, and how to reduce a selection to a specific subset of elements.

Chapter 3: Events — In this chapter, I begin by reviewing the event model as you find it in plain-vanilla JavaScript. You have the traditional event model, the W3C’s event model, and Microsoft’s event model. I discuss the differences between these and why jQuery needed an entirely new Event API to make the situation easier for web developers. Then I present jQuery’s Event API and how you use it.

Chapter 4: Manipulating Content and Attributes — In Chapter 4, you learn how to use the methods that jQuery exposes for working with content, text and HTML, and element attributes. jQuery provides methods for doing just about everything you’d want to do to an element.

Chapter 5: Arrays and Iteration — In Chapter 5, I talk about how you can enumerate over a selection of elements or an array using jQuery. As with everything else, jQuery provides an easier way that requires fewer lines of code to loop over the contents of an array or a selection of elements from the DOM.

Chapter 6: CSS — In this chapter, you learn about the methods that jQuery exposes for working with CSS properties and declarations. jQuery provides intuitive and versatile methods that let you manipulate CSS in a variety of ways.

Chapter 7: AJAX — Chapter 7 elaborates on the methods that jQuery exposes for making AJAX requests from a server, which allows you to request server content without working directly with the XMLHttpRequest object and supports handling server responses in a variety of formats.

Chapter 8: Effects — In Chapter 8, I discuss some helper methods that jQuery exposes for discovering what browser and browser version you’re working with, whether you’re working with a browser that supports the standard W3C box model for CSS, and a variety of odds and ends methods for working with objects, arrays, functions, and strings.

Chapter 9: Plugins — In this chapter, I describe how you can make your own plugins for jQuery.

Part II: jQuery UI

Chapter 10: Implementing Drag-and-Drop — In Chapter 10, I begin my coverage of the jQuery UI library by discussing how you make individual elements draggable and how you make a drag-and-drop interface where you take one element and place it on top of another to create a complete drag-and-drop sequence.

Chapter 11: Drag-and-Drop Sorting — In Chapter 11, I discuss how you make lists sortable using drag-and-drop.

Chapter 12: Selection by Drawing a Box — In Chapter 12, I cover the portion of the jQuery UI library that lets you make a selection by drawing a box with your mouse, just like you would do in your OS’s file management application.

Chapter 13: Accordion UI — In this chapter, I discuss how to make a really neat, polished-looking sidebar that has panes that transition like an accordion. When you mouse over an element, one pane collapses via a slick animation, and another one expands, also via an animation.

Chapter 14: Datepicker — In Chapter 14, I cover how you make a standard form input field into a Datepicker, using jQuery’s Datepicker widget.

Chapter 15: Dialogs — In Chapter 15, I talk about how you create virtual pop-up windows, using the jQuery UI library, that look and act like real pop-up windows but are entirely contained in the same web page that launches them and are built using pure markup, CSS, and JavaScript.

Chapter 16: Tabs — In Chapter 16, I discuss the jQuery UI tab component, which allows you to take a document and split it into several tabs and navigate between those tabs without needing to load another page.

Appendixes — Appendix A contains the answers to chapter exercises. Appendix B through Appendix S contain reference materials for jQuery and jQuery UI.

What You Need to Use This Book

To make use of the examples in this book, you need the following:

Several Internet browsers to test your web pages

Text-editing software or your favorite IDE

Designing content for websites requires being able to reach more than one type of audience. Some of your audience may be using different operating systems or different browsers other than those you have installed on your computer. This book focuses on the most popular browsers available at the time of this writing as supported:

Microsoft Internet Explorer 6 or newer for Windows

Safari for Mac OS X, version 2 or newer

Mozilla Firefox for Mac OS X, Windows, or Linux

Opera for Mac OS X, Windows and Linux, version 9 or newer

Conventions

To help you get the most from the text and keep track of what’s happening, I’ve used a number of conventions throughout the book.

First, be aware that not all the figures referenced in the text actually appear in print. This means, for example, that the screenshots that actually do appear in a chapter might not be numbered in strict sequence. For example, if you look only at the screenshots in Chapter 3, the first is Figure 3-1, and the second is Figure 3-3. There is a reference to Figure 3-2 in the text, but the actual screenshot is not printed. These “missing” screenshots aren’t really missing, though — they are generated by the code download. It’s just that for all intents and purposes, they are identical to the screenshots that are printed before or after them and are therefore not needed in the text.

Try It Out

The Try It Out is an exercise you should work through, following the text in the book.

1. It usually consists of a set of steps.

2. Each step has a number.

3. Follow the steps through with your copy of the database.

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

We highlight with italics new terms and important words when we introduce them.

We show keyboard strokes like this: Ctrl+A.

We show URLs and code within the text like so: persistence.properties.

We present code in the following way:

We use a monofont type with no highlighting for most code examples.

Also, Visual Studio’s code editor provides a rich color scheme to indicate various parts of code syntax. That’s a great tool to help you learn language features in the editor and to help prevent mistakes as you code. To reinforce Visual Studio’s colors, the code listings in this book are colorized using colors similar to what you would see on screen in Visual Studio working with the book’s code. In order to optimize print clarity, some colors have a slightly different hue in print from what you see on screen. But all of the colors for the code in this book should be close enough to the default Visual Studio colors to give you an accurate representation of the colors.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. Once at the site, simply locate the book’s title (either by using the Search box or by using one of the title lists) and click on the Download Code link on the book’s detail page to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book’s ISBN is 978-0-470-22779-4.

Once you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration, and at the same time, you will be helping us provide even higher quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the Book Search Results page, click on the Errata link. On this page, you can view all errata that have been submitted for this book and posted by Wrox editors.

A complete book list including links to errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don’t spot “your” error on the Errata page, click on the Errata Form link and complete the form to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s Errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com, you will find several different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com and click on the Register link.

2. Read the terms of use and click Agree.

3. Complete the required information to join as well as any optional information you wish to provide and click Submit.

4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P, but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click on the “Subscribe to this Forum” icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

Part I: IP/MPLS VPN Service Network Overview

Telecommunication operators must constantly evolve their networks to meet the needs of their customers. Building a converged, high performance, highly available, and highly flexible network to provide multiple services in a cost efficient way is the goal for today’s providers. The new generation of IP/MPLS VPN service-oriented networks has become the operators’ best choice to reach this goal.

Chapter 1: Building Converged Service Networks with IP/MPLS VPN Technology

Chapter 2: IP/MPLS VPN Multi-Service Network Overview

Chapter 1

Introduction to jQuery

JavaScript frameworks have arisen as necessary and useful companions for client-side web development. Without JavaScript frameworks, client-side programming becomes a crater-filled minefield of cross-browser, cross-platform inconsistencies and idiosyncrasies. JavaScript frameworks pave over those craters and inconsistencies to create a seamless, enjoyable client-side programming experience.

The most important hole filled by a JavaScript framework is inconsistencies between Internet Explorer’s and the W3C’s standard Event APIs. jQuery fills in this hole by making a cross-browser Event API that is very similar to the W3C’s, adding some original helpful extensions of its own.

Another hole filled by most of the popular client-side JavaScript frameworks is the ability to select and traverse through nodes in the Document Object Model (DOM) using more than the very remedial selection and traversal APIs that are provided by browsers’ default DOM implementations.

jQuery provides a selection mechanism that uses selector syntax like that used in cascading style sheets. However, not content to support only the standard selectors supported in CSS and even the new Selectors API implementations supported by WebKit and Internet Explorer 8, jQuery again extends the standard to support new, innovative, and useful selectors that make sense when using selectors to select DOM nodes.

In a nutshell, jQuery reduces significantly the amount of JavaScript programming and Q/A (quality assurance) you have to undertake. It takes what might take several lines of code to write, and more often than not reduces that to just one or a few lines of code. jQuery makes your JavaScript more intuitive and easier to understand. jQuery takes JavaScript programming (which at one time had a higher barrier of entry due to complexity and cross-browser, cross-platform idiosyncrasies) and makes it easier and more attractive to average web developers.

Throughout this book, I will discuss jQuery’s Application Programming Interface, or API. We’ll look in depth and up close at each little bit of programming syntax that enables jQuery to do what it does. With each new bit, I also provide simple, to-the-point examples that demonstrate how that bit works. I show you how to write JavaScript applications using jQuery, and by the end of this book, you too will be able to create Web 2.0 applications that function seamlessly across multiple browsers and platforms.

In this chapter, I begin discussion of jQuery by introducing what you get out of jQuery, who develops jQuery, how you obtain jQuery, and how you install jQuery and test that it is ready to use.

As I mentioned in the Introduction, I do not assume that you are a JavaScript expert in this book, but I do assume that you are familiar with basic JavaScript concepts, such as the DOM and attaching events. I will do my best to keep examples simple and to the point and avoid layering on thick programming jargon.

What Does jQuery Do for Me?

jQuery makes many tasks easier. Its simplistic, comprehensive API has the ability to completely change the way you write JavaScript, with the aim of consolidating and eliminating as many common and redundant tasks as possible. jQuery really shines in the following areas:

jQuery makes iterating and traversing the DOM much easier via its various built-in methods for doing the same.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!