original sourse

jQuery 1.4.2 API Cheat Sheet


Data types: * — anything, $ — jQuery object, arr — array, bool — boolean, el — DOM element, fn — function, int — integer, obj — object, str — string, XHR — XMLHttpRequest,

Selectors

Basics

#idSelects a single element with the given id attribute.
elementSelects all elements with the given tag name.
.class, .class.classSelects all elements with the given class.
*Selects all elements.
selector1, selector2Selects the combined results of all the specified selectors.

Hierarchy

ancestor descendantSelects all elements that are descendants of a given ancestor.
parent > childSelects all direct child elements specified by "child" of elements specified by "parent".
prev + nextSelects all next elements matching "next" that are immediately preceded by a sibling "prev".
prev ~ siblingsSelects all sibling elements that follow after the "prev" element, have the same parent, and match the filtering "siblings" selector.

Basic Filters

:firstSelects the first matched element.
:lastSelects the last matched element.
:not(selector)Selects all elements that do not match the given selector.
:evenSelects even elements, zero-indexed.
:oddSelects odd elements, zero-indexed.
:eq(index)Select the element at index n within the matched set.
:gt(index)Select all elements at an index greater than index within the matched set.
:lt(index)Select all elements at an index less than index within the matched set.
:headerSelects all elements that are headers, like h1, h2, h3 and so on.
:animatedSelect all elements that are in the progress of an animation at the time the selector is run.

Content Filters

:contains(text)Select all elements that contain the specified text.
:emptySelect all elements that have no children (including text nodes).
:has(selector)Selects elements which contain at least one element that matches the specified selector.
:parentSelect all elements that are the parent of another element, including text nodes.

Visibility Filters

:hiddenSelects all elements that are hidden.
:visibleSelects all elements that are visible.

Child Filters

:nth-child(expr)Selects all elements that are the nth-child of their parent.
:first-childSelects all elements that are the first child of their parent.
:last-childSelects all elements that are the last child of their parent.
:only-childSelects all elements that are the only child of their parent.

Attribute Filters

[attribute]Selects elements that have the specified attribute, with any value.
[attribute=value]Selects elements that have the specified attribute with a value exactly equal to a certain value.
[attribute!=value]Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.
[attribute^=value]Selects elements that have the specified attribute with a value beginning exactly with a given string.
[attribute$=value]Selects elements that have the specified attribute with a value ending exactly with a given string.
[attribute*=value]Selects elements that have the specified attribute with a value containing the a given substring.
[attribute|=value]Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-).
[attribute~=value]Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.
[attribute][attribute2]Matches elements that match all of the specified attribute filters.

Forms

:inputSelects all input, textarea, select and button elements.
:textSelects all elements of type text.
:passwordSelects all elements of type password
:radioSelects all elements of type radio.
:checkboxSelects all elements of type checkbox.
:submitSelects all elements of type submit.
:imageSelects all elements of type image.
:resetSelects all elements of type reset.
:buttonSelects all button elements and elements of type button.
:fileSelects all elements of type file.

Form Filters

:enabledSelects all elements that are enabled
:disabledSelects all elements that are disabled.
:checkedMatches all elements that are checked.
:selectedSelects all elements that are selected.

Legend

Conventional signs

[obj] — array of objects
1.4+ — new in 1.4
1.4? — changed in 1.4

Core

jQuery function

$.jQuery( selector [, context] ), .jQuery( element ), .jQuery( elementArray ), .jQuery( jQueryObject ), .jQuery( )1.4?Accepts a string containing a CSS selector which is then used to match a set of elements.
$.jQuery( html [, ownerDocument] ), .jQuery( html, props )1.4?Creates DOM elements on the fly from the provided string of raw HTML.
$.jQuery( fn )Binds a function to be executed when the DOM has finished loading.

jQuery Object Accessors

$.each( fn(index, element) )Iterate over a jQuery object, executing a function for each matched element.
num . size ( ) Return the number of DOM elements matched by the jQuery object., . length The number of elements in the jQuery object.
str.selectorA selector representing selector originally passed to jQuery().
el.contextThe DOM node context originally passed to jQuery(); if none was passed then context will likely be the document.
$.eq( index )Reduce the set of matched elements to the one at the specified index.
jQuery.error( str )1.4+Takes a string and throws an exception containing it.
[el],el.get( [index] )Retrieve the DOM elements matched by the jQuery object.
num.index( )1.4?, .index( selector )1.4?, .index( element )Search for a given element from among the matched elements.
$jQuery.pushStack( elements, [name, arguments] )Add a collection of DOM elements onto the jQuery stack.
arr.toArray( )1.4+Retrieve all the DOM elements contained in the jQuery set, as an array.

Interoperability

$jQuery.noConflict( [extreme] )Relinquish jQuery's control of the $ variable.

Attributes

Attributes

str.attr( name )Get the value of an attribute for the first element in the set of matched elements.
$.attr( name, val ), .attr( map ), .attr( name, fn(index, attr) )Set one or more attributes for the set of matched elements.
$.removeAttr( name )Remove an attribute from each element in the set of matched elements.

Class

$.addClass( class ), .addClass( fn(index, class) )1.4?Adds the specified class(es) to each of the set of matched elements.
bool.hasClass( class )Determine whether any of the matched elements are assigned the given class.
$.removeClass( [class] ), .removeClass( fn(index, class) )1.4?Remove one or all classes from each element in the set of matched elements.
$.toggleClass( class [, switch] ), .toggleClass( fn(index, class) [, switch] )1.4?Add or remove a class from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument.

HTML, text

str.html( )Get the HTML contents of the first element in the set of matched elements.
$.html( val ), .html( fn(index, html) )1.4?Set the HTML contents of each element in the set of matched elements.
str.text( )Get the combined text contents of each element in the set of matched elements, including their descendants.
$.text( val ), .text( fn(index, html) )1.4?Set the content of each element in the set of matched elements to the specified text.

Value

str,arr.val( )Get the current value of the first element in the set of matched elements.
$.val( val ), .val( fn() )1.4?Set the value of each element in the set of matched elements.

CSS

CSS

str.css( name )Get the value of a style property for the first element in the set of matched elements.
$.css( name, val ), .css( map ), .css( name, fn(index, val) )1.4?Set one or more CSS properties for the set of matched elements.

Positioning

obj.offset( )Get the current coordinates of the first element in the set of matched elements, relative to the document.
$.offset( coord ), .offset( fn( index, coord ) )1.4+Set the current coordinates of every element in the set of matched elements, relative to the document.
$.offsetParent( )Get the closest ancestor element that is positioned.
obj.position( )Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.
int.scrollTop( )Get the current vertical position of the scroll bar for the first element in the set of matched elements.
$.scrollTop( val )Set the current vertical position of the scroll bar for each of the set of matched elements.
int.scrollLeft( )Get the current horizontal position of the scroll bar for the first element in the set of matched elements.
$.scrollLeft( val )Set the current horizontal position of the scroll bar for each of the set of matched elements.

Height and Width

int.height( )Get the current computed height for the first element in the set of matched elements.
$.height( val ), .height( fn(index, height ) )1.4?Set the CSS height of every matched element.
int.width( )Get the current computed width for the first element in the set of matched elements.
$.width( val ), .width(( fn(index, height ) )1.4?Set the CSS width of each element in the set of matched elements.
int.innerHeight( )Get the current computed height for the first element in the set of matched elements, including padding but not border.
int.innerWidth( )Get the current computed width for the first element in the set of matched elements, including padding but not border.
int.outerHeight( [margin] )Get the current computed height for the first element in the set of matched elements, including padding and border.
int.outerWidth( [margin] )Get the current computed width for the first element in the set of matched elements, including padding and border.

Traversing

Filtering

$.eq( index )Reduce the set of matched elements to the one at the specified index.
$.first( )1.4+Reduce the set of matched elements to the first in the set.
$.last( )1.4+Reduce the set of matched elements to the final one in the set.
$.has( selector ), .has( element )1.4+Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.
$.filter( selector ), .filter( fn(index) )Reduce the set of matched elements to those that match the selector or pass the function's test.
bool.is( selector )Check the current matched set of elements against a selector and return true if at least one of these elements matches the selector.
$.map( fn(index, element) )Pass each element in the current matched set through a function, producing a new jQuery object containing the return values..
$.not( selector ), .not( elements ), .not( fn( index ) )Remove elements from the set of matched elements.
$.slice( start [, end] )Reduce the set of matched elements to a subset specified by a range of indices.

Tree traversal

$.children( [selector] )Get the children of each element in the set of matched elements, optionally filtered by a selector.
$.closest( selector [, context] )1.4?Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree.
arr.closest( selectors [, context] )1.4+Gets an array of all the elements and selectors matched against the current element up through the DOM tree.
$.find( selector )Get the descendants of each element in the current set of matched elements, filtered by a selector.
$.next( [selector] )Get the immediately following sibling of each element in the set of matched elements, optionally filtered by a selector.
$.nextAll( [selector] )Get all following siblings of each element in the set of matched elements, optionally filtered by a selector.
$.nextUntil( [selector] )1.4+Get all following siblings of each element up to but not including the element matched by the selector.
$.offsetParent( )Get all following siblings of each element up to but not including the element matched by the selector.
$.parent( [selector] )Get the parent of each element in the current set of matched elements, optionally filtered by a selector.
$.parents( [selector] )Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.
$.parentsUntil( [selector] )1.4+Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.
$.prev( [selector] )Get the immediately preceding sibling of each element in the set of matched elements, optionally filtered by a selector.
$.prevAll( [selector] )Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector.
$.prevUntil( [selector] )1.4+Get all preceding siblings of each element up to but not including the element matched by the selector.
$.siblings( [selector] )Get the siblings of each element in the set of matched elements, optionally filtered by a selector.

Miscellaneous

$.add( selector [, context] ), .add( elements ), .add( html )1.4?Add elements to the set of matched elements.
$.andSelf( )Add the previous set of elements on the stack to the current set.
$.contents( )Get the children of each element in the set of matched elements, including text nodes.
$.end( )End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.

Manipulation

Inserting Inside

$.append( content ), .append( fn( index, html ) )1.4?Insert content, specified by the parameter, to the end of each element in the set of matched elements.
$.appendTo( target )Insert every element in the set of matched elements to the end of the target.
$.prepend( content ), .prepend( fn( index, html ) )1.4?Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
$.prependTo( target )Insert every element in the set of matched elements to the beginning of the target.

Inserting Outside

$.after( content ), .after( fn() )1.4? Insert content, specified by the parameter, after each element in the set of matched elements.
$.before( content ), .before( fn() )1.4?Insert content, specified by the parameter, before each element in the set of matched elements.
$.insertAfter( target )Insert every element in the set of matched elements after the target.
$.insertBefore( target )Insert every element in the set of matched elements before the target.

Inserting Around

$.unwrap( )1.4+Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
$.wrap( wrappingElement ), .wrap( fn )1.4?Wrap an HTML structure around each element in the set of matched elements.
$.wrapAll(wrappingElement ), .wrapAll( fn )1.4?Wrap an HTML structure around all elements in the set of matched elements.
$.wrapInner( wrappingElement ), .wrapInner( fn )1.4?Wrap an HTML structure around the content of each element in the set of matched elements.

Replacing

$.replaceWith( content ), .replaceWith( fn )1.4?Replace each element in the set of matched elements with the provided new content.
$.replaceAll( selector )Replace each target element with the set of matched elements.

Removing

$.detach( [selector] )1.4+Remove the set of matched elements from the DOM.
$.empty( )Remove all child nodes of the set of matched elements from the DOM.
$.remove( [selector] )Remove the set of matched elements from the DOM.

Copying

$.clone( [withDataAndEvents] )Create a copy of the set of matched elements.

Events

Page Load

$.ready( fn() )Specify a function to execute when the DOM is fully loaded.

Event Handling

$.bind( type [, data ], fn(eventObj) ), .bind( array )1.4?Attach a handler to an event for the elements.
$.one( type [, data ], fn(eventObj) )Attach a handler to an event for the elements. The handler is executed at most once.
$.trigger( event [, data])Execute all handlers and behaviors attached to the matched elements for the given event type.
obj.triggerHandler( event [, data])Execute all handlers attached to an element for an event.
$.unbind( [type] [, fn])Remove a previously-attached event handler from the elements.
$.delegate( selector, eventType, [eventData], handler) 1.4+Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.
$.undelegate( [selector, eventType, [handler]]) 1.4+Remove a handler from the event for all elements which match the current selector, now or in the future, based upon a specific set of root elements.

Live Events

$.live( eventType [, data], fn() )Attach a handler to the event for all elements which match the current selector, now or in the future.
$.die( )1.4+, .die( [eventType] [, fn() ])Remove an event handler previously attached using .live() from the elements.

Interaction Helpers

$.hover( fnIn(eventObj), fnOut(eventObj))Bind two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.
$.toggle( fn(eventObj), fn2(eventObj) [, ...])Bind two or more handlers to the matched elements, to be executed on alternate clicks.

Event Helpers

$
.blur( [fn] ),
.mousedown( [fn] ),
.change( [fn] ),
.mouseenter( [fn] ),
.click( [fn] ),
.mouseleave( [fn] ),
.dblclick( [fn] ),
.mousemove( [fn] ),
.error( [fn] ),
.mouseout( [fn] ),
.focus( [fn] ),
.mouseover( [fn] ),
.focusin( [fn] ),1.4+
.mouseup( [fn] ),
.focusout( [fn] ),1.4+
.resize( [fn] ),
.keydown( [fn] ),
.scroll( [fn] ),
.keypress( [fn] ),
.select( [fn] ),
.keyup( [fn] ),
.submit( [fn] ),
.load( fn ),
.unload( fn )

Event object

event = {
elcurrentTarget,The current DOM element within the event bubbling phase.
*data,Contains the optional data passed to jQuery.fn.bind when the current executing handler was bound.
boolisDefaultPrevented(),Returns whether event.preventDefault() was ever called on this event object.
boolisImmediatePropagationStopped(),Returns whether event.stopImmediatePropagation() was ever called on this event object.
boolisPropagationStopped(),Returns whether event.stopPropagation() was ever called on this event object.
numpageX,The mouse position relative to the left edge of the document.
numpageY,The mouse position relative to the top edge of the document.
preventDefault(),If this method is called, the default action of the event will not be triggered.
elrelatedTarget,The other DOM element involved in the event, if any.
objresult,This attribute contains the last value returned by an event handler that was triggered by this event, unless the value was undefined.
stopImmediatePropagation(),Prevents other event handlers from being called.
stopPropagation(),This method prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
eltarget,The DOM element that initiated the event.
numtimeStamp,This attribute returns the number of milliseconds since January 1, 1970, when the event is triggered.
strtype,Describes the nature of the event.
strwhichFor key or button events, this attribute indicates the specific button or key that was pressed.
}

Effects

Basics

$.show( [ duration [, fn] ]  )Display the matched elements.
$.hide( [ duration [, fn] ]  )Hide the matched elements.
$.toggle( [showOrHide] )Bind two or more handlers to the matched elements, to be executed on alternate clicks.
$.toggle( duration [, fn] )Bind two or more handlers to the matched elements, to be executed on alternate clicks.

Sliding

$.slideDown( duration [, fn] )Display the matched elements with a sliding motion.
$.slideUp( duration [, fn] )Hide the matched elements with a sliding motion.
$.slideToggle( [duration] [, fn] )Display or hide the matched elements with a sliding motion.

Fading

$.fadeIn( duration [, fn] )Display the matched elements by fading them to opaque.
$.fadeOut( duration [, fn] )Hide the matched elements by fading them to transparent.
$.fadeTo( duration, opacity [, fn] )Adjust the opacity of the matched elements.

Custom

$.animate( params [, duration] [, easing] [, fn] )Perform a custom animation of a set of CSS properties.
$.animate( params, options )Perform a custom animation of a set of CSS properties.
$.stop( [clearQueue] [, jumpToEnd] )Stop the currently-running animation on the matched elements.
$.delay( duration [, queueName] )1.4+Set a timer to delay execution of subsequent items in the queue.

Settings

booljQuery.fx.offGlobally disable all animations.

AJAX

Low-Level Interface

XHRjQuery.ajax( options )
  • boolasync = trueBy default, all requests are sent asynchronous (i.e. this is set to true by default).
  • fnbeforeSend( XHR )A pre-callback to modify the XMLHttpRequest object before it is sent.
  • boolcache = trueIf set to false it will force the pages that you request to not be cached by the browser.
  • fncomplete(XHR, status)A function to be called when the request finishes (after success and error callbacks are executed).
  • strcontentTypeWhen sending data to the server, use this content-type. Default is "application/x-www-form-urlencoded", which is fine for most cases.
  • objcontextThis object will be made the context of all Ajax-related callbacks.
  • obj,
    str
    dataData to be sent to the server. It is converted to a query string, if not already a string.
  • fndataFilter( data, type )A function to be used to handle the raw responsed data of XMLHttpRequest.This is a pre-filtering function to sanitize the response.
  • boolglobal = trueWhether to trigger global Ajax event handlers for this request.
  • boolifModified = falseAllow the request to be successful only if the response has changed since the last request.
  • strjsonpOverride the callback function name in a jsonp request.
  • fnjsonpCallbackSpecify the callback function name for a jsonp request.
  • strpasswordA password to be used in response to an HTTP access authentication request.
  • boolprocessData = trueBy default, data passed in to the data option as an object will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded".
  • numtimeoutSet a local timeout (in milliseconds) for the request.
  • strtype = 'GET'The type of request to make ("POST" or "GET"), default is "GET".
  • strurl = curr. pageA string containing the URL to which the request is sent.
  • strusernameA username to be used in response to an HTTP access authentication request.
  • fnxhrCallback for creating the XMLHttpRequest object.
  • strscriptCharsetForces the request to be interpreted as a certain charset.
  • strdataType ? {xml, json, script, html}The type of data that you're expecting back from the server.
  • fnerror( XHR, status, errorThrown )A function to be called if the request fails.
  • fnsuccess( data, status, XHR )A function to be called if the request succeeds.
jQuery.ajaxSetup( options )Set default values for future Ajax requests.

Shorthand Methods

$.load( url [, data] [, fn( responseText, status, XHR )] )Load data from the server and place the returned HTML into the matched element.
XHRjQuery.get( url [, data] [, fn( data, status, XHR )] [, type] )Load data from the server using a HTTP GET request.
XHRjQuery.getJSON( url [, data] [, fn( data, status )] )Load JSON-encoded data from the server using a GET HTTP request.
XHRjQuery.getScript( url [, fn( data, status )] )Load a JavaScript file from the server using a GET HTTP request, then execute it.
XHRjQuery.post( url [, data] [, fn( data, status )] [, type] )Load data from the server using a HTTP POST request.

Global Ajax Event Handlers

$.ajaxComplete( fn( event, XHR, options ) )Register a handler to be called when Ajax requests complete.
$.ajaxError( fn( event, XHR, options, thrownError ) )Register a handler to be called when Ajax requests complete with an error.
$.ajaxSend( fn( event, XHR, options ) )Show a message before an Ajax request is sent.
$.ajaxStart( fn(  ) )Register a handler to be called when the first Ajax request begins.
$.ajaxStop( fn(  ) )Hide a loading message after all the Ajax requests have stopped.
$.ajaxSuccess( fn(event, XHR, options) )Show a message when an Ajax request completes successfully.

Miscellaneous

str.serialize(  )Encode a set of form elements as a string for submission.
[obj].serializeArray(  )Encode a set of form elements as an array of names and values.
strjQuery.param( obj, [traditional] )1.4?Create a serialized representation of an array or object, suitable for use in a URL query string or Ajax request.

Utilities

Browser and Feature Detection

objjQuery.supportA collection of properties that represent the presence of different browser features or bugs.
objjQuery.browserdeprecatedContains flags for the useragent, read from navigator.userAgent.
strjQuery.browser.versiondeprecatedThe version number of the rendering engine for the user's browser.
booljQuery.boxModeldeprecatedStates if the current page, in the user's browser, is being rendered using the W3C CSS Box Model.

Basic operations

objjQuery.each( obj, fn( index, valueOfElement ) )Iterates through the array displaying each number as both a word and numeral.
objjQuery.extend( [deep,] target, obj1 [, objN] )Merge the contents of two or more objects together into the first object.
arrjQuery.grep( array, fn( element, index ) [, invert] )Finds the elements of an array which satisfy a filter function. The original array is not affected.
arrjQuery.makeArray( obj )Convert an array-like object into a true JavaScript array.
arrjQuery.map( array, fn( element, index ) )Translate all items in an array or array-like object to another array of items.
numjQuery.inArray( val, array )Search for a specified value within an array and return its index (or -1 if not found).
arrjQuery.merge( first, second )Merge the contents of two arrays together into the first array.
fnjQuery.noop1.4+An empty function.
fnjQuery.proxy( fn, scope ), jQuery.proxy( scope, name )1.4+Takes a function and returns a new one that will always have a particular context.
arrjQuery.unique( array )Sorts an array of DOM elements, in place, with the duplicates removed. Note that this only works on arrays of DOM elements, not strings or numbers.
strjQuery.trim( str )Remove the whitespace from the beginning and end of a string.
objjQuery.parseJSON( str )1.4+Takes a well-formed JSON string and returns the resulting JavaScript object.

Data functions

$.clearQueue( [name] )1.4+Remove from the queue all items that have not yet been run.
$.dequeue( [name] ), jQuery.dequeue( [name] )Execute the next function on the queue for the matched elements.
objjQuery.data( element, key ), jQuery.data(  )1.4+Store arbitrary data associated with the specified element.
obj.data(  ), .data( key )Store arbitrary data associated with the specified element.
$.data( key, val ), .data( obj )1.4?Store arbitrary data associated with the specified element.
$.removeData( [name] )Remove a previously-stored piece of data.
[fn].queue( [name] ) jQuery.queue( [name] )Show the queue of functions to be executed on the matched elements.
$.queue( [name,] fn( next ) ), jQuery.queue( [name,] fn(  ) )Show the queue of functions to be executed on the matched elements.
$.queue( [name,] queue ), jQuery.queue( [name,] queue )Show the queue of functions to be executed on the matched elements.

Test operations

booljQuery.isArray( obj )Determine whether the argument is an array.
booljQuery.isEmptyObject( obj )1.4+Check to see if an object is empty (contains no properties).
booljQuery.isFunction( obj )Determine if the argument passed is a Javascript function object.
booljQuery.isPlainObject( obj )1.4+