You are previewing jQuery Reference Guide.
O'Reilly logo
jQuery Reference Guide

Book Description

A Comprehensive Exploration of the Popular JavaScript Library

  • Organized menu to every method, function, and selector in the jQuery library

  • Quickly look up features of the jQuery library

  • Understand the anatomy of a jQuery script

  • Extend jQuery's built-in capabilities with plug-ins, and even write your own

In Detail

jQuery is a powerful, yet easy-to-use JavaScript library that helps web developers and designers add dynamic, interactive elements to their sites, smoothing out browser inconsistencies and greatly reducing development time. In this book, the creators of the popular jQuery learning resource, learningquery.com, share their knowledge, experience, and enthusiasm to bring you a comprehensive reference to the popular JavaScript library.

This book offers an organized menu of every jQuery method, function, and selector. Each method and function is introduced with a summary of its syntax and a list of its parameters and return value, followed by a discussion, with examples where applicable, to assist in getting the most out of jQuery and avoiding the pitfalls commonly associated with JavaScript and other client-side languages.

If you're already familiar with JavaScript programming, this book will help you dive right into advanced jQuery concepts. You'll be able to experiment on your own, trusting the pages of this book to provide information on the intricacies of the library, where and when you need it. If you're still hungry for more, the book shows you how to cook up your own extensions with jQuery's elegant plug-in architecture.

This book is a companion to Learning jQuery: Better Interaction Design and Web Development with Simple JavaScript Techniques.Learning jQuery begins with a tutorial to jQuery, followed by an examination of common, real-world client-side problems, and solutions for each of them, making it an invaluable resource for answers to all your jQuery questions.

jQuery Reference Guide digs deeper into the library, taking you through the syntax specifications and following up with a detailed discussion. You'll discover the untapped possibilities that jQuery makes available, and hone your skills as you return to this guide time and again.

In this book, the creators of the popular jQuery learning resource, learningquery.com, share their knowledge, experience, and enthusiasm to bring you a comprehensive reference to the popular JavaScript library.

Visit the jQuery Reference Guide Free Online Edition and read chapter introductions and a free chapter in full.

Table of Contents

  1. jQuery Reference Guide
  2. Credits
  3. About the Authors
  4. About the Reviewers
  5. Preface
    1. What This Book Covers
    2. Who is This Book For?
    3. Conventions
      1. Reader Feedback
      2. Customer Support
      3. Downloading the Example Code for the Book
      4. Errata
      5. Questions
  6. 1. Anatomy of a jQuery Script
    1. A Dynamic Table of Contents
      1. Obtaining jQuery
      2. Setting Up the HTML Document
      3. Writing the jQuery Code
    2. Script Dissection
      1. Selector Expressions
      2. DOM Traversal Methods
      3. DOM Manipulation Methods
      4. Event Methods
      5. Effect Methods
      6. AJAX Methods
      7. Miscellaneous Methods
      8. Plug-In API
    3. Summary
  7. 2. Selector Expressions
    1. CSS Selectors
      1. Element: T
              1. Example
              2. Description
      2. ID: #myid
              1. Examples
              2. Description
      3. Class: .myclass
              1. Examples
              2. Description
      4. Descendant: E F
              1. Examples
              2. Description
      5. Child: E > F
              1. Examples
              2. Description
      6. Adjacent Sibling: E + F
              1. Examples
              2. Description
      7. General Sibling: E ~ F
              1. Examples
              2. Description
      8. Multiple Elements: E,F,G
              1. Examples
              2. Description
      9. Nth Child (:nth-child(n))
              1. Examples
              2. Description
      10. First Child (:first-child)
              1. Examples
              2. Description
      11. Last Child (:last-child)
              1. Examples
              2. Description
      12. Only Child :only-child
              1. Examples
      13. Not :not(s)
              1. Examples
      14. Empty :empty
              1. Examples
              2. Description
      15. Universal: *
              1. Examples
              2. Description
    2. XPath Selectors
      1. Descendant: E//F
              1. Examples
              2. Description
      2. Child: E/F
              1. Examples
              2. Description
      3. Parent: E/..
              1. Examples
              2. Description
      4. Contains: [F]
              1. Examples
              2. Description
    3. Attribute Selectors
      1. Has Attribute: [@foo]
              1. Examples
              2. Description
      2. Attribute Value Equals: [@foo=bar]
              1. Examples
              2. Description
      3. Attribute Value Does Not Equal: [@foo!=bar]
              1. Examples
              2. Description
      4. Attribute Value Begins: [@foo^=bar]
              1. Examples
              2. Description
      5. Attribute Value Ends: [@foo$=bar]
              1. Examples
              2. Description
      6. Attribute Value Contains: [@foo*=bar]
              1. Examples
              2. Description
    4. Form Selectors
    5. Custom Selectors
      1. Even Element (:even) Odd Element (:odd)
        1. Examples
        2. Description
      2. Nth Element (:eq(n), :nth(n))
        1. Examples
        2. Description
      3. Greater Than :gt(n)
        1. Examples
        2. Description
      4. Less Than : lt(n)
              1. Examples
              2. Description
      5. First :first
              1. Examples
              2. Discussion
      6. Last :last
              1. Examples
              2. Description
      7. Parent :parent
              1. Examples
              2. Description
      8. Contains :contains(text)
              1. Examples
              2. Description
      9. Visible :visible
              1. Examples
              2. Discussion
      10. Hidden :hidden
              1. Examples
                1. Description
  8. 3. DOM Traversal Methods
    1. The jQuery Factory Function
    2. $()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Parameters (third version)
              4. Parameters (fourth version)
              5. Parameters (fifth version)
              6. Return Value
              7. Description
              8. Selector Context
              9. Wrapping DOM elements
              10. Cloning jQuery Objects
              11. Creating New Elements
    3. Filtering Methods
      1. .filter()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return Value
              4. Description
              5. Using a Filter Function
      2. .not()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return Value
              4. Description
              5. Removing Specific Elements
      3. .contains()
              1. Parameters
              2. Return Value
              3. Description
      4. .eq()
              1. Parameters
              2. Return Value
              3. Description
      5. .lt()
              1. Parameters
              2. Return Value
              3. Description
      6. .gt()
              1. Parameters
              2. Return Value
              3. Description
    4. Tree Traversal Methods
      1. .find()
              1. Parameters
              2. Return Value
              3. Description
      2. .children()
              1. Parameters
              2. Return Value
              3. Description
      3. .parents()
              1. Parameters
              2. Return Value
              3. Description
      4. .parent()
              1. Parameters
              2. Return Value
              3. Description
      5. .siblings()
              1. Parameters
              2. Return Value
              3. Description
      6. .prev()
              1. Parameters
              2. Return Value
              3. Description
      7. .next()
              1. Parameters
              2. Return Value
              3. Description
    5. Miscellaneous Traversal Methods
      1. .add()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Parameters (third version)
              4. Return Value
              5. Description
      2. .is()
              1. Parameters
              2. Return Value
              3. Description
      3. .end()
              1. Parameters
              2. Return Value
              3. Description
  9. 4. DOM Manipulation Methods
    1. General Attributes
      1. .attr(attribute)
              1. Parameters
              2. Return Value
              3. Description
      2. .attr()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Parameters (third version)
              4. Return Value
              5. Description
              6. .attr(attribute, value)
              7. .attr({map})
              8. .attr(attribute, function)
      3. .removeAttr()
              1. Parameters
              2. Return Value
              3. Description
    2. Style Properties
      1. .css(property)
              1. Parameters
              2. Return Value
              3. Description
      2. .css()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Parameters (third version)
              4. Return Value
              5. Description
      3. .height()
              1. Parameters
              2. Return Value
              3. Description
      4. .height(value)
              1. Parameters
              2. Return Value
              3. Description
      5. .width()
              1. Parameters
              2. Return Value
              3. Description
      6. .width(value)
              1. Parameters
              2. Return Value
              3. Description
    3. Class Attribute
      1. .addClass()
              1. Parameters
              2. Return Value
              3. Description
      2. .removeClass()
              1. Parameters
              2. Return Value
              3. Description
      3. .toggleClass()
              1. Parameters
              2. Return Value
              3. Description
    4. DOM Replacement
      1. .html()
              1. Parameters
              2. Return Value
              3. Description
      2. .html(HTML)
              1. Parameters
              2. Return Value
              3. Description
      3. .text()
              1. Parameters
              2. Return Value
              3. Description
      4. .text(text)
              1. Parameters
              2. Return Value
              3. Description
      5. .val()
              1. Parameters
              2. Return Value
              3. Description
      6. .val(value)
              1. Parameters
              2. Return Value
              3. Description
    5. DOM Insertion, Inside
      1. .prepend()
              1. Parameters
              2. Return Value
              3. Description
      2. .prependTo()
              1. Parameters
              2. Return Value
              3. Description
      3. .append()
              1. Parameters
              2. Return Value
              3. Description
      4. .appendTo()
              1. Parameters
              2. Return Value
              3. Description
    6. DOM Insertion, Outside
      1. .before()
              1. Parameters
              2. Return Value
              3. Description
      2. .insertBefore()
              1. Parameters
              2. Return Value
              3. Description
      3. .after()
              1. Parameters
              2. Return Value
              3. Description
      4. .insertAfter()
              1. Parameters
              2. Return Value
              3. Description
    7. DOM Insertion, Around
      1. .wrap()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return Value
              4. Description
    8. DOM Copying
      1. .clone()
              1. Parameters
              2. Return Value
              3. Description
    9. DOM Removal
      1. .empty()
              1. Parameters
              2. Return Value
              3. Description
      2. .remove()
              1. Parameters
              2. Return Value
              3. Description
  10. 5. Event Methods
    1. Event Handler Attachment
      1. .bind()
              1. Parameters
              2. Return Value
              3. Description
              4. Passing Event Data
      2. .unbind()
              1. Parameters (First Version)
              2. Parameters (Second Version)
              3. Return Value
              4. Description
              5. Using the Event Object
      3. .one()
              1. Parameters
              2. Return Value
              3. Description
      4. .trigger()
              1. Parameters
              2. Return Value
              3. Description
    2. Document Loading
      1. $()
              1. Parameters
              2. Return Value
              3. Description
      2. .load()
              1. Parameters
              2. Return Value
              3. Description
      3. .unload()
              1. Parameters
              2. Return Value
              3. Description
      4. .error()
              1. Parameters
              2. Return Value
              3. Description
    3. Mouse Events
      1. .mousedown()
              1. Parameters (First Version)
              2. Return Value
              3. Description
      2. .mouseup()
              1. Parameters (First Version)
              2. Return Value
              3. Description
      3. .click()
              1. Parameters (First Version)
              2. Return Value
              3. Description
      4. .dblclick()
              1. Parameters (First Version)
              2. Return Value
              3. Description
      5. .toggle()
              1. Parameters
              2. Return Value
      6. .mouseover()
              1. Parameters (First Version)
              2. Return Value
      7. .mouseout()
              1. Parameters (First Version)
              2. Return Value
      8. .hover()
              1. Parameters
              2. Return Value
      9. .mousemove()
              1. Parameters (First Version)
              2. Return Value
    4. Form Events
      1. .focus()
              1. Parameters (First Version)
              2. Return Value
      2. .blur()
              1. Parameters (First Version)
              2. Return Value
      3. .change()
              1. Parameters (First Version)
              2. Return Value
      4. .select()
              1. Parameters (First Version)
              2. Return Value
      5. .submit()
              1. Parameters (First Version)
              2. Return Value
              3. Description
    5. Keyboard Events
      1. .keydown()
              1. Parameters (First Version)
              2. Return Value
      2. .keypress()
              1. Parameters (First Version)
              2. Return Value
              3. Description
      3. .keyup()
              1. Parameters (First Version)
              2. Return Value
    6. Browser Events
      1. .resize()
              1. Parameters (First Version)
              2. Return Value
      2. .scroll()
              1. Parameters
              2. Return Value
  11. 6. Effect Methods
    1. Pre-Packaged Effects
      1. .show()
              1. Parameters
              2. Return Value
              3. Description
      2. .hide()
              1. Parameters
              2. Return Value
              3. Description
      3. .toggle()
              1. Parameters
              2. Return Value
              3. Description
      4. .slideDown()
              1. Parameters
              2. Return Value
              3. Description
      5. .slideUp()
              1. Parameters
              2. Return Value
              3. Description
      6. .slideToggle()
              1. Parameters
              2. Return Value
              3. Description
      7. .fadeIn()
              1. Parameters
              2. Return Value
              3. Description
      8. .fadeOut()
              1. Parameters
              2. Return Value
              3. Description
      9. .fadeTo()
              1. Parameters
              2. Return Value
              3. Description
    2. Customized Effects
      1. .animate()
              1. Parameters
              2. Return Value
              3. Description
  12. 7. AJAX Methods
    1. Low-Level Interface
      1. $.ajax()
              1. Parameters
              2. Return Value
              3. Description
      2. $.ajaxSetup()
              1. Parameters
              2. Return Value
              3. Description
    2. Shorthand Methods
      1. $.get()
              1. Parameters
              2. Return Value
              3. Description
      2. $.getIfModified()
              1. Parameters
              2. Return Value
              3. Description
      3. .load()
              1. Parameters
              2. Return Value
              3. Description
      4. .loadIfModified()
              1. Parameters
              2. Return Value
              3. Description
      5. $.post()
              1. Parameters
              2. Return Value
              3. Description
      6. $.getJSON()
              1. Parameters
              2. Return Value
              3. Description
      7. $.getScript()
              1. Parameters
              2. Return Value
              3. Descritpion
    3. Global AJAX Event Handlers
      1. .ajaxComplete()
              1. Parameters
              2. Return Value
              3. Description
      2. .ajaxError()
              1. Parameters
              2. Return Value
              3. Description
      3. .ajaxSend()
              1. Parameters
              2. Return Value
              3. Description
      4. .ajaxStart()
              1. Parameters
              2. Return Value
              3. Description
      5. .ajaxStop()
              1. Parameters
              2. Return Value
              3. Description
      6. .ajaxSuccess()
              1. Parameters
              2. Return Value
              3. Description
    4. Helper Function
      1. .serialize()
              1. Parameters
              2. Return Value
              3. Description
  13. 8. Miscellaneous Methods
    1. Setup Methods
      1. $.browser
              1. Parameters
              2. Return Value
              3. Description
      2. $.noConflict()
              1. Parameters
              2. Return Value
              3. Description
    2. DOM Element Methods
      1. .length
              1. Parameters
              2. Return Value
              3. Description
      2. .size()
              1. Parameters
              2. Return Value
              3. Description
      3. .get()
              1. Parameters
              2. Return Value
              3. Description
      4. .index()
              1. Parameters
              2. Return Value
              3. Description
    3. Collection Manipulation
      1. .each()
              1. Parameters (First Version)
              2. Return Value (First Version)
              3. Parameters (Second Version)
              4. Return Value (Second Version)
              5. Description
      2. $.grep()
              1. Parameters
              2. Return Value
              3. Description
      3. $.map()
              1. Parameters
              2. Return Value
              3. Description
      4. $.merge()
              1. Parameters
              2. Return Value
              3. Description
      5. $.unique()
              1. Parameters
              2. Return Value
              3. Description
      6. $.extend()
              1. Parameters
              2. Return Value
              3. Description
      7. $.trim()
              1. Parameters
              2. Return Value
              3. Description
  14. 9. Plug-In API
    1. Using a Plug-in
    2. Developing a Plug-in
      1. Object Method
              1. Components
              2. Discussion
      2. Global Function
              1. Components (First Version)
              2. Components (Second Version)
              3. Discussion
      3. Selector Expression
              1. Components
              2. Discussion
      4. Easing Style
              1. Components
              2. Discussion
    3. Example: Maintaining Multiple Event Logs
    4. Summary
  15. 10. Dimensions Plug-In
    1. Size Methods
      1. .height()
              1. Parameters
              2. Return Value
              3. Discussion
      2. .width()
              1. Parameters
              2. Return Value
              3. Description
      3. .innerHeight()
              1. Parameters
              2. Return Value
              3. Description
      4. .innerWidth()
              1. Parameters
              2. Return Value
              3. Description
      5. .outerHeight()
              1. Parameters
              2. Return Value
              3. Discussion
      6. .outerWidth()
              1. Parameters
              2. Return Value
              3. Description
    2. Position Methods
      1. .scrollTop()
              1. Parameters
              2. Return Value
              3. Discussion
      2. .scrollTop(value)
              1. Parameters
              2. Return Value
              3. Description
      3. .scrollLeft()
              1. Parameters
              2. Return Value
              3. Description
      4. .scrollLeft(value)
              1. Parameters
              2. Return Value
              3. Discussion
      5. .offset()
              1. Parameters (First Version)
              2. Parameters (Second Version)
              3. Return Value (First Version)
              4. Return Value (Second Version)
              5. Description
      6. .position()
              1. Parameters (First Version)
              2. Parameters (Second Version)
              3. Return Value (First Version)
              4. Return Value (Second Version)
              5. Description
  16. 11. Form Plug-In
    1. AJAX Form Submission
      1. .ajaxSubmit()
              1. Parameters (First Version)
              2. Parameters (Second Version)
              3. Return Value
              4. Discussion
      2. .ajaxForm()
              1. Parameters
              2. Return Value
              3. Discussion
      3. .ajaxFormUnbind()
              1. Parameters
              2. Return Value
              3. Discussion
    2. Retrieving Form Values
      1. .formToArray()
              1. Parameters
              2. Return Value
              3. Discussion
      2. .formSerialize()
              1. Parameters
              2. Return Value
              3. Discussion
      3. .fieldSerialize()
              1. Parameters
              2. Return Value
              3. Discussion
      4. .fieldValue()
              1. Parameters (First Version)
              2. Parameters (Second Version)
              3. Return Value
              4. Discussion
    3. Form Manipulation
      1. .clearForm()
              1. Parameters
              2. Return Value
              3. Discussion
      2. .clearFields()
              1. Parameters
              2. Return Value
              3. Discussion
      3. .resetForm()
              1. Parameters
              2. Return Value
              3. Discussion
  17. A. Online Resources
    1. jQuery Documentation
              1. jQuery Wiki
              2. jQuery API
              3. jQuery API Browser
              4. Visual jQuery
              5. Web Developer Blog
    2. JavaScript Reference
              1. Mozilla Developer Center
              2. Dev.Opera
              3. Quirksmode
              4. JavaScript Toolbox
    3. JavaScript Code Compressors
              1. Packer
              2. JSMin
              3. Pretty Printer
    4. (X)HTML Reference
              1. W3C Hypertext Markup Language Home Page
    5. CSS Reference
              1. W3C Cascading Style Sheets Home Page
              2. Mezzoblue CSS Cribsheet
              3. Position Is Everything
    6. XPath Reference
              1. W3C XML Path Language Version 1.0 Specification
              2. TopXML XPath Reference
              3. MSDN XPath Reference
    7. Useful Blogs
              1. The jQuery Blog
              2. Learning jQuery
              3. Jack Slocum's Blog
              4. Web Standards with Imagination
              5. Snook
              6. Wait Till I Come
              7. DOM Scripting
              8. As Days Pass By
              9. A List Apart
              10. Particletree
              11. The Strange Zen of JavaScript
    8. Web Development Frameworks Using jQuery
  18. B. Development Tools
    1. Tools for Firefox
              1. Firebug
              2. Web Developer Toolbar
              3. Venkman
              4. Regular Expressions Tester
    2. Tools for Internet Explorer
              1. Microsoft Internet Explorer Developer Toolbar
              2. Microsoft Visual Web Developer
              3. DebugBar
              4. Drip
    3. Tools for Safari
              1. Web Inspector
              2. Drosera
    4. Other Tools
              1. Firebug Lite
              2. Charles