You are previewing Learning jQuery Third Edition.
O'Reilly logo
Learning jQuery Third Edition

Book Description

Create better interaction, design, and web development with simple JavaScript techniques

  • An introduction to jQuery that requires minimal programming experience

  • Detailed solutions to specific client-side problems

  • Revised and updated version of this popular jQuery book

  • In Detail

    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.

    Learning jQuery Third Edition is revised and updated for version 1.6 of jQuery. You will learn 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.

    Starting with an introduction to jQuery, you will first be shown how to write a functioning jQuery program in just three lines of code. Learn how to add impact to your actions through a set of simple visual effects and to create, copy, reassemble, and embellish content using jQuery's DOM modification methods. The book will step you through many detailed, real-world examples, and even equip you to extend the jQuery library itself with your own plug-ins.

    Table of Contents

    1. Learning jQuery Third Edition
      1. Table of Contents
      2. Learning jQuery Third Edition
      3. Credits
      4. Foreword
      5. About the Authors
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What This Book Covers
        2. What you need for this book
        3. Who this book is for
          1. History of the jQuery project
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Getting Started
        1. What jQuery does
        2. Why jQuery works well
        3. Our first jQuery-powered web page
          1. Downloading jQuery
          2. Setting up jQuery in an HTML document
          3. Adding our jQuery code
            1. Finding the poem text
            2. Injecting the new class
            3. Executing the code
          4. The finished product
        4. Plain JavaScript vs. jQuery
        5. Development tools
          1. Firebug
        6. Summary
      10. 2. Selecting Elements
        1. The Document Object Model
        2. The $() function
        3. CSS selectors
          1. Styling list-item levels
          2. Attribute selectors
          3. Styling links
        4. Custom selectors
          1. Styling alternate rows
          2. Form selectors
        5. DOM traversal methods
          1. Styling specific cells
          2. Chaining
        6. Accessing DOM elements
        7. Summary
          1. Further reading
        8. Exercises
      11. 3. Handling Events
        1. Performing tasks on page load
          1. Timing of code execution
          2. Multiple scripts on one page
          3. Shortcuts for code brevity
          4. Passing an argument to the .ready() callback
        2. Simple events
          1. A simple style switcher
          2. Enabling the other buttons
          3. Event handler context
          4. Further consolidation
          5. Shorthand events
        3. Compound events
          1. Showing and hiding advanced features
          2. Highlighting clickable items
        4. The journey of an event
          1. Side effects of event bubbling
        5. Altering the journey: the event object
          1. Event targets
          2. Stopping event propagation
          3. Default actions
          4. Event delegation
          5. Methods for event delegation
        6. Removing an event handler
          1. Event namespacing
          2. Rebinding events
        7. Simulating user interaction
          1. Keyboard events
        8. Summary
          1. Further reading
        9. Exercises
      12. 4. Styling and Animating
        1. Inline CSS modification
        2. Basic hide and show
        3. Effects and speed
          1. Speeding in
          2. Fading in and fading out
          3. Sliding up and sliding down
          4. Compound effects
        4. Creating custom animations
          1. Building effects by hand
          2. Animating multiple properties at once
            1. Positioning with CSS
        5. Simultaneous versus queued effects
          1. Working with a single set of elements
            1. Bypassing the queue
            2. Manual queueing
          2. Working with multiple sets of elements
            1. Callbacks
          3. In a nutshell
        6. Summary
          1. Further reading
        7. Exercises
      13. 5. Manipulating the DOM
        1. Manipulating attributes
          1. Non-class attributes
            1. Value callbacks
          2. DOM element properties
        2. DOM tree manipulation
          1. The $() function revisited
          2. Creating new elements
          3. Inserting new elements
          4. Moving elements
          5. Wrapping elements
          6. Inverted insertion methods
        3. Copying elements
          1. Cloning for pull quotes
        4. Content getter and setter methods
          1. Further style adjustments
        5. DOM manipulation methods in a nutshell
        6. Summary
          1. Further reading
        7. Exercises
      14. 6. Sending Data with Ajax
        1. Loading data on demand
          1. Appending HTML
          2. Working with JavaScript objects
            1. Retrieving JSON
            2. Global jQuery functions
            3. Executing a script
          3. Loading an XML document
        2. Choosing a data format
        3. Passing data to the server
          1. Performing a GET request
          2. Performing a POST request
          3. Serializing a form
        4. Delivering different content for Ajax requests
        5. Keeping an eye on the request
        6. Error handling
        7. Ajax and events
        8. Security limitations
          1. Using JSONP for remote data
        9. Additional options
          1. The low-level Ajax method
          2. Modifying default options
          3. Loading parts of an HTML page
        10. Summary
          1. Further reading
        11. Exercises
      15. 7. Using Plugins
        1. Finding plugins and help
        2. How to use a plugin
          1. Downloading and referencing the Cycle plugin
          2. Simple plugin use
          3. Specifying plugin method parameters
          4. Parameter defaults
          5. Other types of plugins
            1. Custom selectors
            2. Global function plugins
        3. The jQuery UI plugin library
          1. Effects
            1. Color animations
            2. Class animations
            3. Advanced easing
            4. Additional effects
          2. Interaction components
          3. Widgets
          4. jQuery UI ThemeRoller
        4. Summary
        5. Exercises
      16. 8. Developing Plugins
        1. Use of the $ alias in plugins
        2. Adding new global functions
          1. Adding multiple functions
        3. Adding jQuery object methods
          1. Object method context
          2. Implicit iteration
          3. Method chaining
        4. Method parameters
          1. Parameter maps
          2. Default parameter values
          3. Callback functions
          4. Customizable defaults
        5. The jQuery UI widget factory
          1. Creating a widget
          2. Destroying widgets
          3. Enabling and disabling widgets
          4. Accepting widget options
          5. Adding sub-methods
          6. Triggering widget events
        6. Plugin design recommendations
          1. Plugin distribution
        7. Summary
        8. Exercises
      17. 9. Advanced Selectors and Traversing
        1. Selecting and traversing revisited
          1. Dynamic table filtering
          2. Table row striping
          3. Combining filtering and striping
          4. More selectors and traversal methods
        2. Customizing and optimizing selectors
          1. Writing a custom selector plugin
          2. Selector performance
            1. Sizzle selector implementation
            2. Testing selector speed
        3. DOM traversal under the hood
          1. jQuery object properties
          2. The DOM element stack
          3. Writing a DOM traversal method plugin
          4. DOM traversal performance
            1. Improving performance using chaining
            2. Improving performance using caching
        4. Summary
          1. Further reading
        5. Exercises
      18. 10. Advanced Events
        1. Events revisited
          1. Loading additional pages of data
          2. Displaying data on hover
        2. Event delegation
          1. Using jQuery's delegation methods
          2. Choosing a delegation method
          3. Delegating early
          4. Using a context argument
        3. Custom events
          1. Infinite scrolling
          2. Custom event parameters
        4. Throttling events
          1. Other ways to perform throttling
        5. Special events
          1. More about special events
        6. Summary
          1. Further reading
        7. Exercises
      19. 11. Advanced Effects
        1. Animation revisited
        2. Observing and interrupting animations
          1. Determining the animation state
          2. Halting a running animation
            1. Caution when halting animations
        3. Global effect properties
          1. Globally disabling all effects
          2. Fine-tuning animation smoothness
          3. Defining effect durations
        4. Multi-property easing
        5. Deferred objects
          1. Animation promises
        6. Summary
          1. Further reading
        7. Exercises
      20. 12. Advanced DOM Manipulation
        1. Sorting table rows
          1. Server-side sorting
          2. Ajax sorting
          3. JavaScript sorting
        2. Moving and inserting elements, revisited
          1. Adding links around existing text
          2. Sorting simple JavaScript arrays
          3. Sorting DOM elements
        3. Storing data alongside DOM elements
          1. Performing additional precomputation
          2. Storing non-string data
          3. Alternating sort directions
        4. Using HTML5 custom data attributes
        5. Sorting and building rows with JSON
          1. Modifying the JSON object
          2. Rebuilding content on demand
        6. Advanced attribute manipulation
          1. Shorthand element creation
          2. DOM manipulation hooks
            1. Writing a CSS hook
        7. Summary
          1. Further reading
        8. Exercises
      21. 13. Advanced Ajax
        1. Progressive enhancement with Ajax
          1. Harvesting JSONP data
        2. Ajax error handling
        3. The jqXHR object
          1. Ajax promises
          2. Caching responses
        4. Throttling Ajax requests
        5. Extending Ajax capabilities
          1. Data type converters
          2. Ajax prefilters
          3. Alternate transports
        6. Summary
          1. Further reading
        7. Exercises
      22. A. JavaScript Closures
        1. Inner functions
          1. The great escape
          2. Variable scoping
        2. Interactions between closures
        3. Closures in jQuery
          1. Arguments to $(document).ready()
          2. Event handlers
          3. Binding handlers in loops
          4. Named and anonymous functions
        4. Memory leak hazards
          1. Accidental reference loops
          2. The Internet Explorer memory leak problem
            1. The good news
        5. Summary
      23. B. Testing JavaScript with QUnit
        1. Downloading QUnit
        2. Setting up the document
        3. Organizing tests
        4. Adding and running tests
          1. Asynchronous testing
        5. Other types of tests
        6. Practical considerations
          1. Further reading
        7. Summary
      24. C. Quick Reference
        1. Selector expressions
          1. Simple CSS
          2. Position among siblings
          3. Position among matched elements
          4. Attributes
          5. Forms
          6. Other custom selectors
        2. DOM traversal methods
          1. Filtering
          2. Descendants
          3. Siblings
          4. Ancestors
          5. Collection manipulation
          6. Working with selected elements
        3. Event methods
          1. Binding
          2. Shorthand binding
          3. Special shorthands
          4. Triggering
          5. Shorthand triggering
          6. Utility
        4. Effect methods
          1. Predefined effects
          2. Custom animations
          3. Queue manipulation
        5. DOM manipulation methods
          1. Attributes and properties
          2. Content
          3. CSS
          4. Dimensions
          5. Insertion
          6. Replacement
          7. Removal
          8. Copying
          9. Data
        6. Ajax methods
          1. Issuing requests
          2. Request monitoring
          3. Configuration
          4. Utilities
        7. Deferred objects
          1. Object creation
          2. Methods of deferred objects
          3. Methods of promise objects
        8. Miscellaneous properties and functions
          1. Properties of the jQuery object
          2. Arrays and objects
          3. Object introspection
          4. Other
      25. Index