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

Book Description

A comprehensive exploration of the popular JavaScript library

  • Quickly look up features of the jQuery library

  • Step through each function, method, and selector expression in the jQuery library with an easy-to-follow approach

  • Understand the anatomy of a jQuery script

  • Write your own plug-ins using jQuery's powerful plug-in architecture

  • In Detail

    To make optimal use of jQuery, it's good to keep in mind the breadth of capabilities it provides. You can add dynamic, interactive elements to your sites with reduced development time using jQuery. If you are looking for a comprehensive reference guide to this popular JavaScript library, this book is for you.

    Revised and updated for version 1.4 of jQuery, 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.

    In this book you will be provided information about the latest features of jQuery that include Sizzle Selector, Native event delegation, Event triggering, DOM manipulation, and many more. You won't be confined to built-in functionality, you'll be able to examine jQuery's plug-in architecture and we discuss both how to use plug-ins and how to write your own. 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.

    This book is a companion to Learning jQuery 1.3. Learning jQuery 1.3 begins with a tutorial to jQuery, where the authors share their knowledge, experience, and enthusiasm about jQuery to help you get the most from the library and to make your web applications shine.

    jQuery 1.4 Reference Guide digs deeper into the library, taking you through the syntax specifications and following up with detailed discussions. You'll discover the untapped possibilities that jQuery 1.4 makes available, and polish 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 this popular JavaScript library.

    Table of Contents

    1. jQuery 1.4 Reference Guide
      1. jQuery 1.4 Reference Guide
      2. Credits
      3. About the Authors
      4. About the Reviewers
      5. 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. Errata
          2. Piracy
          3. 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. Examples
            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 expressions (E, F, G)
            1. Examples
            2. Description
          9. Numbered child (:nth-child(n/even/odd/expr))
            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(E))
            1. Examples
          14. Empty (:empty)
            1. Examples
            2. Description
          15. Universal (*)
            1. Examples
            2. Description
        2. Attribute selectors
          1. Attribute ([foo])
            1. Examples
          2. Attribute equals ([foo=bar])
            1. Examples
            2. Description
          3. Attribute does not equal ([foo!=bar])
            1. Examples
            2. Description
          4. Attribute begins with ([foo^=bar])
            1. Examples
            2. Description
          5. Attribute ends with ([foo$=bar])
            1. Examples
          6. Attribute contains ([foo*=bar])
            1. Examples
            2. Description
          7. Attribute contains word ([foo~=bar])
            1. Examples
            2. Description
          8. Attribute contains prefix ([foo|=bar])
            1. Examples
            2. Description
        3. Form selectors
        4. Custom selectors
          1. Element at index (:eq(n))
            1. Examples
            2. Description
          2. Greater than (:gt(n))
            1. Examples
            2. Description
          3. Less than (:lt(n))
            1. Examples
            2. Description
          4. First (:first)
            1. Examples
            2. Description
          5. Last (:last)
            1. Examples
            2. Description
          6. Even element (:even)
            1. Examples
            2. Description
          7. Odd element (:odd)
            1. Examples
            2. Description
          8. Is parent (:parent)
            1. Examples
            2. Description
          9. Contains text (:contains(text))
            1. Examples
            2. Description
          10. Contains element (:has(E))
            1. Examples
            2. Description
          11. Visible (:visible)
            1. Examples
            2. Description
          12. Hidden (:hidden)
            1. Examples
            2. Description
          13. Header element (:header)
            1. Examples
          14. Currently animating (:animated)
            1. Examples
      8. 3. DOM Traversal Methods
        1. The jQuery function
          1. $()
            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
              1. Selector context
              2. Using DOM elements
              3. Cloning jQuery objects
              4. Creating new elements
        2. Filtering methods
          1. .filter()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
              1. Using a filter function
          2. .not()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Parameters (third version)
            4. Return value
            5. Description
              1. Removing specific elements
          3. .has()
            1. Parameters
            2. Return value
            3. Description
          4. .eq()
            1. Parameters
            2. Return value
            3. Description
          5. .first()
            1. Parameters
            2. Return value
            3. Description
          6. .last()
            1. Parameters
            2. Return value
            3. Description
          7. .slice()
            1. Parameters
            2. Return value
            3. Description
              1. Negative indices
        3. 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. .parentsUntil()
            1. Parameters
            2. Return value
            3. Description
          5. .parent()
            1. Parameters
            2. Return value
            3. Description
          6. .closest()
            1. Parameters
            2. Return value
            3. Description
          7. .offsetParent()
            1. Parameters
            2. Return value
            3. Description
          8. .siblings()
            1. Parameters
            2. Return value
            3. Description
          9. .prev()
            1. Parameters
            2. Return value
            3. Description
          10. .prevAll()
            1. Parameters
            2. Return value
            3. Description
          11. .prevUntil()
            1. Parameters
            2. Return value
            3. Description
          12. .next()
            1. Parameters
            2. Return value
            3. Description
          13. .nextAll()
            1. Parameters
            2. Return value
            3. Description
          14. .nextUntil()
            1. Parameters
            2. Return value
            3. Description
        4. 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
          4. .andSelf()
            1. Parameters
            2. Return value
            3. Description
          5. .map()
            1. Parameters
            2. Return value
            3. Description
          6. .contents()
            1. Parameters
            2. Return value
            3. Description
      9. 4. DOM Manipulation Methods
        1. General attributes
          1. .attr() (getter)
            1. Parameters
            2. Return value
            3. Description
          2. .attr() (setter)
            1. Parameters (first version)
            2. Parameters (second version)
            3. Parameters (third version)
            4. Return value
            5. Description
              1. Setting a simple attribute
              2. Setting several attributes at once
              3. Computed attribute values
          3. .removeAttr()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
        2. Style properties
          1. .css() (getter)
            1. Parameters
            2. Return value
            3. Description
          2. .css() (setter)
            1. Parameters (first version)
            2. Parameters (second version)
            3. Parameters (third version)
            4. Return value
            5. Description
          3. .height() (getter)
            1. Parameters
            2. Return value
            3. Description
          4. .height() (setter)
            1. Parameters
            2. Return value
            3. Description
          5. .innerHeight()
            1. Parameters
            2. Return value
            3. Description
          6. .outerHeight()
            1. Parameters
            2. Return value
            3. Description
          7. .width() (getter)
            1. Parameters
            2. Return value
            3. Description
          8. .width() (setter)
            1. Parameters
            2. Return value
            3. Description
          9. .innerWidth()
            1. Parameters
            2. Return value
            3. Description
          10. .outerWidth()
            1. Parameters
            2. Return value
            3. Description
          11. .offset() (getter)
            1. Parameters
            2. Return value
            3. Description
          12. .offset() (setter)
            1. Parameters
            2. Return value
            3. Description
          13. .position()
            1. Parameters
            2. Return value
            3. Description
          14. .scrollTop() (getter)
            1. Parameters
            2. Return value
            3. Description
          15. .scrollTop() (setter)
            1. Parameters
            2. Return value
          16. .scrollLeft() (getter)
            1. Parameters
            2. Return value
            3. Description
          17. .scrollLeft() (setter)
            1. Parameters
            2. Return value
        3. Class attributes
          1. .hasClass()
            1. Parameters
            2. Return value
            3. Description
          2. .addClass()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
          3. .removeClass()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
          4. .toggleClass()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Parameters (third version)
            4. Return value
            5. Description
        4. DOM replacement
          1. .html() (getter)
            1. Parameters
            2. Return value
            3. Description
          2. .html() (setter)
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
          3. .text() (getter)
            1. Parameters
            2. Return value
            3. Description
          4. .text() (setter)
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
          5. .val() (getter)
            1. Parameters
            2. Return value
            3. Description
          6. .val() (setter)
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
          7. .replaceWith()
            1. Parameters
            2. Return value
            3. Description
          8. .replaceAll()
            1. Parameters
            2. Return value
            3. Description
          9. DOM insertion, inside
            1. .prepend()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return value
              4. Description
            2. .prependTo()
              1. Parameters
              2. Return value
              3. Description
            3. .append()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return value
              4. Description
            4. .appendTo()
              1. Parameters
              2. Return value
              3. Description
          10. DOM insertion, outside
            1. .before()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return value
              4. Description
            2. .insertBefore()
              1. Parameters
              2. Return value
              3. Description
            3. .after()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return value
              4. Description
            4. .insertAfter()
              1. Parameters
              2. Return value
              3. Description
          11. DOM insertion, around
            1. .wrap()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return value
              4. Description
            2. .wrapAll()
              1. Parameters
              2. Return value
              3. Description
            3. .wrapInner()
              1. Parameters (first version)
              2. Parameters (second version)
              3. Return value
              4. Description
          12. DOM copying
            1. .clone()
              1. Parameters
              2. Return value
              3. Description
          13. DOM removal
            1. .empty()
              1. Parameters
              2. Return value
              3. Description
            2. .remove()
              1. Parameters
              2. Return value
              3. Description
            3. .detach()
              1. Parameters
              2. Return value
              3. Description
            4. .unwrap()
              1. Parameters
              2. Return value
              3. Description
      10. 5. Event Methods
        1. Event handler attachment
          1. .bind()
            1. Parameters
            2. Return value
            3. Description
              1. Event handlers
              2. The event object
              3. Passing event data
          2. .unbind()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
              1. Using namespaces
              2. Using the event object
          3. .one()
            1. Parameters
            2. Return value
            3. Description
          4. .trigger()
            1. Parameters
            2. Return value
            3. Description
          5. .triggerHandler()
            1. Parameters
            2. Return value
            3. Description
          6. .live()
            1. Parameters
            2. Return value
            3. Description
              1. Event delegation
              2. Caveats
          7. .die()
            1. Parameters
            2. Return value
            3. Description
        2. Document loading
          1. .ready()
            1. Parameters
            2. Return value
            3. Description
              1. Aliasing the jQuery namespace
            4. .load()
              1. Parameters
              2. Return value
              3. Description
            5. .unload()
              1. Parameters
              2. Return value
              3. Description
            6. .error()
              1. Parameters
              2. Return value
              3. Description
          2. 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
              3. Description
            6. .mouseover()
              1. Parameters (first version)
              2. Return value
              3. Description
            7. .mouseout()
              1. Parameters (first version)
              2. Return value
              3. Description
            8. .mouseenter()
              1. Parameters (first version)
              2. Return value
              3. Description
            9. .mouseleave()
              1. Parameters (first version)
              2. Return value
              3. Description
            10. .hover()
              1. Parameters
              2. Return value
              3. Description
            11. .mousemove()
              1. Parameters (first version)
              2. Return value
              3. Description
          3. Form events
            1. .focus()
              1. Parameters (first version)
              2. Return value
              3. Description
            2. .blur()
              1. Parameters (first version)
              2. Return value
              3. Description
            3. .change()
              1. Parameters (first version)
              2. Return value
              3. Description
            4. .select()
              1. Parameters (first version)
              2. Return value
              3. Description
            5. .submit()
              1. Parameters (first version)
              2. Return value
              3. Description
          4. Keyboard events
            1. .keydown()
              1. Parameters (first version)
              2. Return value
              3. Description
            2. .keypress()
              1. Parameters (first version)
              2. Return value
              3. Description
            3. .keyup()
              1. Parameters (first version)
              2. Return value
              3. Description
          5. Browser events
            1. .resize()
              1. Parameters (first version)
              2. Return value
              3. Description
            2. .scroll()
              1. Parameters (first version)
              2. Return value
              3. Description
      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 (first version)
            2. Parameters (second version)
            3. Return value
            4. 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 (first version)
            2. Parameters (second version)
            3. Return value
            4. Description
          2. .stop()
            1. Parameters
            2. Return value
            3. Description
          3. .delay()
            1. Parameters
            2. Return value
            3. Description
          4. .queue()
            1. Parameters (first version)
            2. Parameters (second version)
            3. Parameters (third version)
            4. Return value (first version)
            5. Return value (second and third versions)
            6. Description
          5. .dequeue()
            1. Parameters
            2. Return value
            3. Description
          6. .clearQueue()
            1. Parameter
            2. Return value
            3. Description
      12. 7. AJAX Methods
        1. Low-level interface
          1. $.ajax()
            1. Parameters
            2. Return value
            3. Description
              1. Callback functions
              2. Data types
              3. Sending data to the server
              4. Advanced options
          2. $.ajaxSetup()
            1. Parameters
            2. Return value
            3. Description
        2. Shorthand methods
          1. $.get()
            1. Parameters
            2. Return value
            3. Description
          2. .load()
            1. Parameters
            2. Return value
            3. Description
              1. Loading page fragments
          3. $.post()
            1. Parameters
            2. Return value
            3. Description
          4. $.getJSON()
            1. Parameters
            2. Return value
            3. Description
          5. $.getScript()
            1. Parameters
            2. Return value
            3. Description
        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 functions
          1. .serialize()
            1. Parameters
            2. Return value
            3. Description
          2. .serializeArray()
            1. Parameters
            2. Return value
            3. Description
      13. 8. Miscellaneous Methods
        1. Setup methods
          1. $.noConflict()
            1. Parameters
            2. Return value
            3. Description
        2. DOM element methods
          1. .size()
            1. Return value
            2. Description
          2. .get()
            1. Parameters
            2. Return value
            3. Description
          3. .index()
            1. Parameters (first version)
            2. Return value (first version)
            3. Parameters (second version)
            4. Return value (second version)
            5. Parameters (third version)
            6. Return value (third version)
            7. 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. $.makeArray()
            1. Parameters
            2. Return value
            3. Description
          4. $.inArray()
            1. Parameters
            2. Return value
            3. Description
          5. $.map()
            1. Parameters
            2. Return value
            3. Description
          6. $.merge()
            1. Parameters
            2. Return value
            3. Description
          7. $.unique()
            1. Parameters
            2. Return value
            3. Description
          8. $.extend()
            1. Parameters
            2. Return value
            3. Description
          9. $.trim()
            1. Parameters
            2. Return value
            3. Description
          10. $.param()
            1. Parameters
            2. Return value
            3. Description
        4. Introspection
          1. $.isArray()
            1. Parameters
            2. Return value
          2. $.isFunction()
            1. Parameters
            2. Return value
          3. $.isPlainObject()
            1. Parameters
            2. Return value
          4. $.isEmptyObject()
            1. Parameters
            2. Return value
          5. $.isXMLDoc()
            1. Parameters
            2. Return value
        5. Data storage
          1. .data()
            1. Parameters (first version)
            2. Return value (first version)
            3. Parameters (second version)
            4. Return value (second version)
            5. Parameters (third version)
            6. Return value (third version)
            7. Description
          2. .removeData()
            1. Parameters
            2. Return value
            3. Description
      14. 9. jQuery Properties
        1. Global properties
          1. $.browser
          2. $.support
            1. $.support.boxModel
            2. $.support.cssFloat
            3. $.support.hrefNormalized
            4. $.support.htmlSerialize
            5. $.support.leadingWhitespace
            6. $.support.noCloneEvent
            7. $.support.objectAll
            8. $.support.opacity
            9. $.support.scriptEval
            10. $.support.style
            11. $.support.tbody
          3. jQuery object properties
            1. .length
            2. .selector
            3. .context
      15. 10. The Plug-in API
        1. Using a plug-in
        2. Developing a plug-in
          1. Object method
            1. Components
            2. Description
          2. Global function
            1. Components (first and second versions)
            2. Components (third version)
            3. Description
              1. Plug-ins with a single function
              2. Plug-ins with multiple functions
            4. Example: A simple print function
          3. Selector expression
            1. Components
            2. Description
        3. Plug-in conventions
          1. Use of the $ alias
          2. Naming conventions
          3. API standardization
      16. 11. Alphabetical Quick Reference
        1. Selector expressions
        2. Methods
        3. Properties
      17. A. Online Resources
        1. jQuery documentation
          1. Official jQuery documentation
          2. jQuery API browser
          3. Adobe AIR jQuery API Viewer
        2. JavaScript reference
          1. Mozilla Developer Center
          2. Client-Side JavaScript Reference
          3. MSDN Reference
          4. Dev.Opera
          5. Quirksmode
          6. JavaScript Toolbox
          7. comp.lang.javascript FAQ
        3. JavaScript code compressors
          1. JSMin
          2. YUI Compressor
          3. Google Closure Compiler
          4. Packer
        4. JavaScript code decompressors
          1. Pretty Printer
          2. JavaScript beautifier
        5. (X)HTML reference
          1. W3C Hypertext Markup Language Home Page
        6. CSS reference
          1. W3C Cascading Style Sheets Home Page
          2. Mezzoblue CSS Crib Sheet
          3. Position Is Everything
        7. Useful blogs
          1. The jQuery blog
          2. Learning jQuery
          3. jQuery for Designers
          4. Ajaxian
          5. John Resig
          6. JavaScript Ant
          7. Robert's talk
          8. Snook
          9. Paul Irish
          10. NCZOnline
          11. I Can't
          12. DOM scripting
          13. Steve Souders
          14. As days pass by
          15. A List Apart
        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 Internet Explorer 8 Developer Tools
          3. Microsoft Visual Web Developer Express
          4. dynaTrace AJAX Edition
          5. DebugBar
          6. Drip
        3. Tools for Safari
          1. Develop menu
        4. Tools for Opera
          1. Dragonfly
        5. Other tools
          1. Firebug Lite
          2. NitobiBug
          3. TextMate jQuery Bundle
          4. jQuerify Bookmarklet
          5. Charles
          6. Fiddler
          7. Sloppy
          8. JS Bin
          9. Bespin
          10. Aptana