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,
SelectorsBasics#idSelects a single element with the given id attribute.
elementSelects all elements with the given tag name.
*Selects all elements.
selector1, selector2Selects the combined results of all the specified selectors.
Hierarchyancestor 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.
LegendConventional signs[obj] — array of objects
1.4+ — new in 1.4
1.4? — changed in 1.4
|
CorejQuery 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 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.
el.contextThe DOM node context originally passed to jQuery(); if none was passed then context will likely be the document.
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.
InteroperabilityAttributesAttributesClass$.addClass( class ), .addClass( fn(index, class) )1.4?Adds the specified class(es) to each of the set of matched elements.
$.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.
CSSCSSstr.css( name )Get the value of a style property for the first element in the set of matched elements.
Positioningobj.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.
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$.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.
|
TraversingFiltering$.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.
ManipulationInserting 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.
$.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.
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.
Replacing$.replaceWith( content ), .replaceWith( fn )1.4?Replace each element in the set of matched elements with the provided new content.
RemovingCopying |
EventsPage LoadEvent 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.
$.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.
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] ),
.mouseup( [fn] ),
.resize( [fn] ),
.keydown( [fn] ),
.scroll( [fn] ),
.keypress( [fn] ),
.select( [fn] ),
.keyup( [fn] ),
.submit( [fn] ),
.load( fn ),
.unload( fn )
Event object
event = {
*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.
objresult,This attribute contains the last value returned by an event handler that was triggered by this event, unless the value was undefined.
stopPropagation(),This method prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
numtimeStamp,This attribute returns the number of milliseconds since January 1, 1970, when the event is triggered.
strwhichFor key or button events, this attribute indicates the specific button or key that was pressed.
}
EffectsBasics$.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.
SlidingFadingCustom$.animate( params [, duration] [, easing] [, fn] )Perform a custom animation of a set of CSS properties.
$.delay( duration [, queueName] )1.4+Set a timer to delay execution of subsequent items in the queue.
Settings |
AJAXLow-Level InterfaceXHRjQuery.ajax( options )
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.
MiscellaneousstrjQuery.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.
UtilitiesBrowser and Feature DetectionobjjQuery.supportA collection of properties that represent the presence of different browser features or bugs.
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 operationsobjjQuery.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.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).
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.
objjQuery.parseJSON( str )1.4+Takes a well-formed JSON string and returns the resulting JavaScript object.
Data functions$.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.
[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 |