Overview

jQuery is a cross-platform general purpose JavaScript library, focused around querying specific elements of pages and performing DOM manipulations on them.

Case Studies

Gotchas

  • $.extend is slow, and is called from many places within JQuery (including the event handling). For this reason, it's usually good to avoid using JQuery methods within mousemove handlers or code that may be called from mousemove handlers.
  • A jQuery collection may contain zero elements if the selector is mistyped or does not match any elements on the page. All operations on this collection simply do nothing instead of resulting in an error. Watch for this: if nothing happens when you expect something to, you may have a mistyped selector.
  • Traversal & filtering methods are destructive, which means that you can get surprising results if you assign a JQuery collection to a variable and then operate on it (your operations will be seen by all other variables referencing it). The intended usage pattern is to perform all your manipulations at once, using successive filters, and then call .end() to restore the collection's state to the previous version.

Tips & Tricks

  • JQuery collections have a 'length' property that contains the number of elements matched, and may be indexed by number. $(selector)[0] is a convenient way to get the first (or only) matching DOM element within the collection.

Alternatives

Other Resources

 
jquery.txt · Last modified: 2008/04/27 17:51 by twk
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki