You are previewing jQuery: A Beginner's Guide.
O'Reilly logo
jQuery: A Beginner's Guide

Book Description

Essential Skills--Made Easy!

Learn the fundamentals of jQuery programming in no time. jQuery: A Beginner's Guide starts with the basics--from including the library in an HTML document to element selection, event handling, and CSS style manipulation. Next, it's on to JavaScript and the DOM, animation and effects, the Event object, and form validation. The book then delves into AJAX and plugins and covers more advanced techniques such as debugging and unit testing. Get started with jQuery right away using this fast-paced tutorial!

Designed for Easy Learning

  • Key Skills & Concepts -- Chapter-opening lists of specific skills covered in the chapter
  • Ask the Expert -- Q&A sections filled with bonus information and helpful tips
  • Try This -- Hands-on exercises that show you how to apply your skills
  • Notes -- Extra information related to the topic being covered
  • Tips -- Helpful reminders or alternate ways of doing things
  • Cautions -- Errors and pitfalls to avoid
  • Annotated Syntax -- Example code with commentary that describes the programming techniques being illustrated
  • Self Tests -- Chapter-ending quizzes to reinforce your skills

Ready-to-use code at www.mhprofessional.com/computingdownload

Table of Contents

  1. Cover
  2. About the Author
  3. Title Page
  4. Copyright Page
  5. Dedication
  6. Contents at a Glance
  7. Content
  8. ACKNOWLEDGMENTS
  9. INTRODUCTION
  10. 1 Getting Started with jQuery
    1. What You Need to Know
      1. Basic HTML and CSS Knowledge
      2. Basic Text Editor and Web Browser Knowledge
      3. Basic JavaScript Knowledge
    2. What Is jQuery?
      1. What Can jQuery Do?
      2. Who Can Use jQuery?
    3. Why jQuery Is Useful
      1. Accessible
      2. Browser Inconsistencies
      3. Additional Functionality
    4. Begin Using jQuery
      1. Obtaining jQuery
      2. Using a CDN
      3. Local or CDN: Which Method Should I Use?
    5. Your First jQuery Script
      1. Locating the Proper Element
      2. Waiting for the Document to Be Ready
    6. Try This 1-1: Add Another Class
    7. Resources for Help
    8. Chapter 1 Self Test
  11. 2 Selecting Elements in the Document
    1. The $() Function
    2. CSS Basics
      1. Selecting Elements
      2. Selecting Elements Using IDs and Classes
    3. Using CSS Selectors
      1. The All, Element, Class, and ID Selectors
      2. The Descendant Selector
      3. The Child Selector
      4. The First Child, Last Child, and Nth Child Selectors
      5. The Not Selector
      6. Attribute Selectors
      7. The Remaining CSS Selectors
    4. Try This 2-1: Add Another Class
    5. Using Extended jQuery Selectors
      1. The Attribute Not Equal Selector
      2. The First, Last, and Element at Index Selectors
      3. The Even and Odd Selectors
    6. Try This 2-2: More Selection Practice
    7. Chapter 2 Self Test
  12. 3 Event Handling
    1. Waiting for the Document to Be Ready
      1. ready() vs. load()
      2. What Is the Difference?
      3. Using the $ Argument with ready()
    2. Handling an Event
      1. Basic Event Handling
    3. jQuery Events
      1. Mouse Events
      2. Keyboard Events
      3. Other Events
      4. Event Capturing and Bubbling
      5. Using the on() Method to Handle Events
      6. Other Events
    4. Try This 3-1: Add Event Handlers
    5. Triggering Events
    6. Try This 3-2: Trigger Practice
    7. Chapter 3 Self Test
  13. 4 Working with Styles
    1. CSS Rules
    2. The css() Method
      1. Getting Values
      2. Setting Values
    3. Class Methods
      1. The addClass() and removeClass() Methods
      2. The toggleClass() Method
      3. The hasClass() Method
    4. Try This 4-1: Use toggleClass()
    5. Size and Position Methods
      1. The width() and height() Methods
      2. The innerWidth() and innerHeight() Methods
      3. The outerWidth() and outerHeight() Methods
      4. The offset() Method
      5. The position() Method
      6. The scrollLeft() and scrollTop() Methods
    6. Try This 4-2: Use offset()
    7. Chapter 4 Self Test
  14. 5 JavaScript and the Document Object Model
    1. Basic JavaScript
      1. Comments
      2. Variables and Data Types
      3. Operators
      4. Flow Control Statements
      5. Functions
      6. Arrays
      7. Objects
    2. Try This 5-1: Use JavaScript with jQuery
    3. The Document Object Model (DOM)
    4. The DOM and jQuery
      1. Attributes
      2. Creating New Elements
      3. Copying Elements
      4. Removing Elements
    5. Try This 5-2: Add Elements
    6. Chapter 5 Self Test
  15. 6 Animations and Effects
    1. Show and Hide Animation Methods
      1. The show() and hide() Methods
      2. The slideDown() and slideUp() Methods
      3. The fadeIn() and fadeOut() Methods
    2. Callback Functions
    3. Try This 6-1: Practice with slideDown()
    4. Creating Custom Animations
      1. Property/Value Map
      2. Duration Values
      3. Easing Values
      4. Callback Function
      5. The Second Form of animate()
      6. Updating the FAQ Page
    5. Try This 6-2: Chain on a Custom Animation
    6. Stopping Animations
    7. Chapter 6 Self Test
  16. 7 The Event Object
    1. The Event Object in jQuery
      1. Browser Inconsistencies
      2. About the Event Object
    2. Event Properties
      1. The type Property
      2. The timeStamp Property
      3. The which Property
    3. Try This 7-1: Practice Using which
    4. Event Methods
      1. The stopPropagation() Method
      2. The stopImmediatePropagation() Method
      3. The “is” Methods
    5. Try This 7-2: Practice Stopping Propagation
    6. Chapter 7 Self Test
  17. 8 The DOM and Forms
    1. Form Element Values
      1. The val() Method
    2. Form Events
      1. The blur() and focus() Methods
      2. The change() Method
      3. The select() Method
      4. The submit() Method
    3. Regular Expressions
      1. Creating Regular Expressions
      2. Testing Strings Against Regular Expressions
      3. Using Flags
    4. Try This 8-1: Practice Using Regular Expressions
    5. Form Validation
      1. Helpful HTML for Forms
      2. Helping the User
      3. Validating the Form
    6. Try This 8-2: Practice Validation
    7. Chapter 8 Self Test
  18. 9 Working with AJAX
    1. Introduction to AJAX
    2. Creating AJAX Requests
      1. Retrieving HTML
      2. Retrieving XML
      3. Retrieving JSON
    3. Try This 9-1: Practice Basic AJAX
    4. Two-Way AJAX Requests
      1. Using Get and Post Requests
      2. Handling Errors
      3. Form Input Serialization
    5. Try This 9-2: Practice Serialization
    6. Security Issues and Further Information
      1. Further Information
    7. Chapter 9 Self Test
  19. 10 Using Plugins
    1. Introduction to jQuery Plugins
    2. Using a Plugin
      1. Downloading and Installing a Plugin
      2. Calling the Method
      3. Setting Plugin Options
    3. Try This 10-1: Practice Using a Plugin
    4. Helpful Plugins
      1. jQuery UI
      2. Parsley.js
      3. ParamQuery Grid
      4. jKit
      5. jCanvas
    5. Try This 10-2: Practice with jQuery UI
    6. Chapter 10 Self Test
  20. 11 Creating Plugins
    1. Global Methods and the $ Alias
      1. Ensuring $ Is Available
      2. Creating Methods and Minimizing Naming Conflicts
    2. Creating jQuery Object Methods
      1. Extending the jQuery Object
      2. Using Implicit Iteration and Returning a jQuery Object
      3. User Customization with an Options Map
    3. Try This 11-1: Practice Plugin Options
    4. Adding a Callback Function
    5. Try This 11-2: Practice with Callbacks
    6. Chapter 11 Self Test
  21. 12 Advanced Techniques and Further Resources
    1. Debugging
      1. Simple Alerts
      2. Browser Developer Tools
      3. Using a Lint Tool
    2. Try This 12-1: Practice Using a Lint Tool
    3. Unit Testing
    4. Additional Resources
      1. jQuery Resources
      2. JavaScript Resources
      3. Contacting the Author
    5. Chapter 12 Self Test
  22. A Answers to Self Tests
    1. Chapter 1: Getting Started with jQuery
    2. Chapter 2: Selecting Elements in the Document
    3. Chapter 3: Event Handling
    4. Chapter 4: Working with Styles
    5. Chapter 5: JavaScript and the Document Object Model
    6. Chapter 6: Animations and Effects
    7. Chapter 7: The Event Object
    8. Chapter 8: The DOM and Forms
    9. Chapter 9: Working with AJAX
    10. Chapter 10: Using Plugins
    11. Chapter 11: Creating Plugins
    12. Chapter 12: Advanced Techniques and Further Resources
  23. Index