You are previewing Learning jQuery - Fourth Edition.
O'Reilly logo
Learning jQuery - Fourth Edition

Book Description

Add to your current website development skills with this brilliant guide to JQuery. This step by step course needs little prior JavaScript knowledge so is suitable for beginners and more seasoned developers alike.

  • 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.

    LearningjQuery - Fourth Edition is revised and updated version 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 take 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 - Fourth Edition
      1. Table of Contents
      2. Learning jQuery - Fourth 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
        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. Making our first jQuery-powered web page
          1. Downloading jQuery
          2. Deciding on the version of jQuery to use
          3. Setting up jQuery in an HTML document
          4. Adding our jQuery code
            1. Finding the poem text
            2. Injecting the new class
            3. Executing the code
          5. The finished product
        4. Plain JavaScript versus jQuery
        5. Using development tools
          1. Chrome Developer Tools
        6. Summary
      10. 2. Selecting Elements
        1. Understanding the DOM
        2. Using the $() function
        3. CSS selectors
          1. Styling list-item levels
        4. Attribute selectors
          1. Styling links
        5. Custom selectors
          1. Styling alternate rows
          2. Finding elements based on textual content
          3. Form selectors
        6. DOM traversal methods
          1. Styling specific cells
          2. Chaining
        7. Accessing DOM elements
        8. Summary
          1. Further reading
        9. Exercises
      11. 3. Handling Events
        1. Performing tasks on page load
          1. Timing of code execution
          2. Handling multiple scripts on one page
          3. Alternate syntax for .ready()
          4. Passing an argument to the .ready() callback
        2. Handling simple events
          1. A simple style switcher
          2. Enabling the other buttons
          3. Making use of the event handler context
          4. Consolidating code using the event context
          5. Shorthand events
          6. Showing and hiding advanced features
        3. Event propagation
          1. The journey of an event
          2. Side effects of event bubbling
        4. Altering the journey – the event object
          1. Event targets
          2. Stopping event propagation
          3. Preventing default actions
          4. Delegating events
          5. Using built-in event-delegation capabilities
        5. Removing an event handler
          1. Giving namespaces to event handlers
          2. Rebinding events
        6. Simulating user interaction
          1. Reacting to keyboard events
        7. Summary
          1. Further reading
        8. Exercises
      12. 4. Styling and Animating
        1. Modifying CSS with inline properties
          1. Setting computed style-property values
          2. Using vendor-specific style properties
        2. Hiding and showing elements
        3. Effects and duration
          1. Speeding in
          2. Fading in and fading out
          3. Sliding up and sliding down
          4. Toggling visibility
        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. Queuing effects manually
          2. Working with multiple sets of elements
            1. Queuing with callbacks
          3. In a nutshell
        6. Summary
          1. Further reading
        7. Exercises
      13. 5. Manipulating the DOM
        1. Manipulating attributes and properties
          1. Non-class attributes
            1. Value callbacks
          2. DOM element properties
          3. The value of form controls
        2. DOM tree manipulation
          1. The $() function revisited
          2. Creating new elements
          3. Inserting new elements
          4. Moving elements
          5. Wrapping elements
            1. Explicit iteration
          6. Using inverted insertion methods
        3. Copying elements
          1. Cloning for pull quotes
        4. Content getter and setter methods
        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. Using 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. Exploring 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. Using a plugin
          1. Downloading and referencing the Cycle plugin
          2. Calling a plugin method
          3. Specifying plugin method parameters
          4. Modifying parameter defaults
        3. Other types of plugins
          1. Custom selectors
          2. Global function plugins
        4. 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
        5. The jQuery Mobile plugin library
          1. HTML5 custom data attributes
          2. Mobile navigation
          3. Delivering multiple pages in one document
          4. Interactive elements
            1. List views
            2. Toolbar buttons
          5. Advanced features
        6. Summary
        7. Exercises
      16. 8. Developing Plugins
        1. Using the dollar ($) alias in plugins
        2. Adding new global functions
          1. Adding multiple functions
            1. Extending the global jQuery object
            2. Isolating functions within namespaces
        3. Adding jQuery object methods
          1. Object method context
          2. Implicit iteration
          3. Enabling method chaining
        4. Providing flexible method parameters
          1. The options object
          2. Default parameter values
          3. Callback functions
          4. Customizable defaults
        5. Creating plugins with the jQuery UI widget factory
          1. Creating a widget
          2. Destroying widgets
          3. Enabling and disabling widgets
          4. Accepting widget options
          5. Adding submethods
          6. Triggering widget events
        6. Plugin design recommendations
          1. Distributing a plugin
        7. Summary
        8. Exercises
      17. 9. Advanced Selectors and Traversing
        1. Selecting and traversing revisited
          1. Dynamic table filtering
          2. Striping table rows
          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. The 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 with caching
        4. Summary
          1. Further reading
        5. Exercises
      18. 10. Advanced Events
        1. Revisiting events
          1. Loading additional pages of data
          2. Displaying data on hovering
        2. Event delegation
          1. Using jQuery's delegation capabilities
          2. Choosing a delegation scope
          3. Delegating early
        3. Defining custom events
          1. Infinite scrolling
          2. Custom event parameters
        4. Throttling events
          1. Other ways to perform throttling
        5. Extending events
          1. More about special events
        6. Summary
        7. Further reading
        8. 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. Using global effect properties
          1. Disabling all effects
          2. Defining effect durations
        4. Multiproperty easing
        5. Using deferred objects
          1. Animation promises
        6. Taking fine-grained control of animations
        7. Summary
          1. Further reading
        8. Exercises
      20. 12. Advanced DOM Manipulation
        1. Sorting table rows
          1. Sorting tables on the server
          2. Sorting tables using Ajax
          3. Sorting tables within the browser
        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. Revisiting attribute manipulation
          1. Using shorthand element-creation syntax
          2. DOM manipulation hooks
            1. Writing a CSS hook
        7. Summary
          1. Further reading
        8. Exercises
      21. 13. Advanced Ajax
        1. Implementing progressive enhancement with Ajax
          1. Harvesting JSONP data
        2. Handling Ajax errors
        3. Using the jqXHR object
          1. Ajax promises
          2. Caching responses
        4. Throttling Ajax requests
        5. Extending Ajax capabilities
          1. Data type converters
          2. Adding Ajax prefilters
          3. Defining alternate transports
        6. Summary
          1. Further reading
        7. Exercises
      22. A. JavaScript Closures
        1. Creating inner functions
          1. Calling inner functions from elsewhere
          2. Understanding variable scope
        2. Handling interactions between closures
        3. Creating closures in jQuery
          1. Passing arguments to $(document).ready()
          2. Assigning event handlers
          3. Binding handlers in loops
          4. Giving names to functions
        4. Handling memory-leak hazards
          1. Avoiding accidental reference loops
          2. Managing loops between the DOM and JavaScript
            1. Disentangling reference loops with jQuery
        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. Miscellaneous 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. Triggering
          4. Shorthand triggering
          5. 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