jQuery 1.4 API Cheat Sheet

Selectors

Basics

#id
Selects a single element with the given id attribute.
element
.class, .class.class
*
Selects all elements.
selector1, selector2

Hierarchy

ancestor descendant
parent > child
prev + next
prev ~ siblings

Basic Filters

:first
:last
:not(selector)
:even
:odd
Selects odd elements, zero-indexed.
:eq(index)
:gt(index)
:lt(index)
:header
:animated

Content Filters

:contains(text)
:empty
:has(selector)
:parent

Visibility Filters

:hidden
:visible

Child Filters

:nth-child(expr)
:first-child
:last-child
:only-child

Attribute Filters

[attribute]
[attribute=value]
[attribute!=value]
[attribute^=value]
[attribute$=value]
[attribute*=value]
[attribute|=value]
[attribute~=value]
[attribute][attribute2]

Forms

:input
:text
:password
:radio
:checkbox
:submit
:image
:reset
:button
:file

Form Filters

:enabled
:disabled
:checked
:selected

Legend

Conventional signs

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

Data types

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

Core

jQuery function

$.jQuery( selector [, context] ), .jQuery( element ), .jQuery( elementArray ), .jQuery( jQueryObject ), .jQuery( )1.4∗
$.jQuery( html [, ownerDocument] ), .jQuery( html, props )1.4∗
$.jQuery( fn )

jQuery Object Accessors

$.each( fn(index, element) )
num.size( ) , .length
The number of elements in the jQuery object.
str.selector
A selector representing selector originally passed to jQuery().
el.context
The DOM node context originally passed to jQuery(); if none was passed then context will likely be the document.
$.eq( index )
jQuery.error( str )1.4+
[el],el.get( [index] )
num.index( )1.4∗, .index( selector )1.4∗, .index( element )
$jQuery.pushStack( elements, [name, arguments] )
arr.toArray( )1.4+

Interoperability

$jQuery.noConflict( [extreme] )

Attributes

Attributes

str.attr( name )
$.attr( name, val ), .attr( map ), .attr( name, fn(index, attr) )
$.removeAttr( name )

Class

$.addClass( class ), .addClass( fn(index, class) )1.4∗
bool.hasClass( class )
$.removeClass( [class] ), .removeClass( fn(index, class) )1.4∗
$.toggleClass( class [, switch] ), .toggleClass( fn(index, class) [, switch] )1.4∗

HTML, text

str.html( )
$.html( val ), .html( fn(index, html) )1.4∗
str.text( )
$.text( val ), .text( fn(index, html) )1.4∗

Value

str,arr.val( )
$.val( val ), .val( fn() )1.4∗

CSS

CSS

str.css( name )
$.css( name, val ), .css( map ), .css( name, fn(index, val) )1.4∗

Positioning

obj.offset( )
$.offset( coord ), .offset( fn( index, coord ) )1.4+
$.offsetParent( )
obj.position( )
int.scrollTop( )
$.scrollTop( val )
int.scrollLeft( )
$.scrollLeft( val )

Height and Width

int.height( )
$.height( val ), .height( fn(index, height ) )1.4∗
int.width( )
$.width( val ), .width(( fn(index, height ) )1.4∗
int.innerHeight( )
int.innerWidth( )
int.outerHeight( [margin] )
int.outerWidth( [margin] )

Traversing

Filtering

$.eq( index )
$.first( )1.4+
$.last( )1.4+
$.has( selector ), .has( element )1.4+
$.filter( selector ), .filter( fn(index) )
bool.is( selector )
$.map( fn(index, element) )
$.not( selector ), .not( elements ), .not( fn( index ) )
Remove elements from the set of matched elements.
$.slice( start [, end] )

Tree traversal

$.children( [selector] )
$.closest( selector [, context] )1.4∗
arr.closest( selectors [, context] )1.4+
$.find( selector )
$.next( [selector] )
$.nextAll( [selector] )
$.nextUntil( [selector] )1.4+
$.offsetParent( )
$.parent( [selector] )
Get the parent of each element in the current set of matched elements, optionally filtered by a selector.
$.parents( [selector] )
$.parentsUntil( [selector] )1.4+
$.prev( [selector] )
$.prevAll( [selector] )
$.prevUntil( [selector] )1.4+
$.siblings( [selector] )

Miscellaneous

$.add( selector [, context] ), .add( elements ), .add( html )1.4∗
$.andSelf( )
$.contents( )
$.end( )

Manipulation

Inserting Inside

$.append( content ), .append( fn( index, html ) )1.4∗
$.appendTo( target )
$.prepend( content ), .prepend( fn( index, html ) )1.4∗
$.prependTo( target )

Inserting Outside

$.after( content ), .after( fn() )1.4∗
$.before( content ), .before( fn() )1.4∗
$.insertAfter( target )
$.insertBefore( target )

Inserting Around

$.unwrap( )1.4+
$.wrap( wrappingElement ), .wrap( fn )1.4∗
$.wrapAll(wrappingElement ), .wrapAll( fn )1.4∗
$.wrapInner( wrappingElement ), .wrapInner( fn )1.4∗

Replacing

$.replaceWith( content ), .replaceWith( fn )1.4∗
$.replaceAll( selector )

Removing

$.detach( [selector] )1.4+
$.empty( )
$.remove( [selector] )

Copying

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

Events

Page Load

$.ready( fn() )

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) )
$.trigger( event [, data])
obj.triggerHandler( event [, data])
$.unbind( [type] [, fn])
$.delegate( selector, eventType, [eventData], handler) 1.4+
$.undelegate( [selector, eventType, [handler]]) 1.4+

Live Events

$.live( eventType [, data], fn() )
$.die( )1.4+, .die( [eventType] [, fn() ])

Interaction Helpers

$.hover( fnIn(eventObj), fnOut(eventObj))
$.toggle( fn(eventObj), fn2(eventObj) [, ...])

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,
*data,
boolisDefaultPrevented(),
boolisImmediatePropagationStopped(),
boolisPropagationStopped(),
numpageX,
numpageY,
preventDefault(),
elrelatedTarget,
objresult,
stopImmediatePropagation(),
stopPropagation(),
eltarget,
numtimeStamp,
strtype,
strwhich
}

Effects

Basics

$.show( [ duration [, fn] ]  )
$.hide( [ duration [, fn] ]  )
$.toggle( [showOrHide] )
$.toggle( duration [, fn] )

Sliding

$.slideDown( duration [, fn] )
$.slideUp( duration [, fn] )
$.slideToggle( [duration] [, fn] )

Fading

$.fadeIn( duration [, fn] )
$.fadeOut( duration [, fn] )
$.fadeTo( duration, opacity [, fn] )

Custom

$.animate( params [, duration] [, easing] [, fn] )
$.animate( params, options )
Perform a custom animation of a set of CSS properties.
$.stop( [clearQueue] [, jumpToEnd] )
$.delay( duration [, queueName] )1.4+

Settings

booljQuery.fx.off

AJAX

Low-Level Interface

XHRjQuery.ajax( options )
  • boolasync = true
  • fnbeforeSend( XHR )
  • boolcache = true
  • fncomplete(XHR, status)
  • strcontentType
  • objcontext
  • obj, strdata
  • 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 = true
  • boolifModified = false
  • strjsonp
  • fnjsonpCallback
  • strpassword
  • boolprocessData = true
  • numtimeout
  • strtype = 'GET'
  • strurl = curr. page
  • strusername
  • fnxhr
  • strscriptCharset
  • strdataType ∈ {xml, json, script, html}
  • fnerror( XHR, status, errorThrown )
  • fnsuccess( data, status, XHR )
jQuery.ajaxSetup( options )

Shorthand Methods

$.load( url [, data] [, fn( responseText, status, XHR )] )
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 )] )
XHRjQuery.getScript( url [, fn( data, status )] )
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 ) )
$.ajaxError( fn( event, XHR, options, thrownError ) )
$.ajaxSend( fn( event, XHR, options ) )
$.ajaxStart( fn(  ) )
$.ajaxStop( fn(  ) )
$.ajaxSuccess( fn(event, XHR, options) )

Miscellaneous

str.serialize(  )
[obj].serializeArray(  )
strjQuery.param( obj, [traditional] )1.4∗

Utilities

Browser and Feature Detection

objjQuery.support
objjQuery.browserdeprecated
strjQuery.browser.versiondeprecated
booljQuery.boxModeldeprecated

Basic operations

objjQuery.each( obj, fn( index, valueOfElement ) )
objjQuery.extend( [deep,] target, obj1 [, objN] )
arrjQuery.grep( array, fn( element, index ) [, invert] )
arrjQuery.makeArray( obj )
arrjQuery.map( array, fn( element, index ) )
numjQuery.inArray( val, array )
arrjQuery.merge( first, second )
Merge the contents of two arrays together into the first array.
fnjQuery.noop1.4+
fnjQuery.proxy( fn, scope ), jQuery.proxy( scope, name )1.4+
arrjQuery.unique( array )
strjQuery.trim( str )
objjQuery.parseJSON( str )1.4+

Data functions

$.clearQueue( [name] )1.4+
$.dequeue( [name] ), jQuery.dequeue( [name] )
objjQuery.data( element, key ), jQuery.data(  )1.4+
obj.data(  ), .data( key )
$.data( key, val ), .data( obj )1.4∗
$.removeData( [name] )
[fn].queue( [name] ) jQuery.queue( [name] )
$.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 )

Test operations

booljQuery.isArray( obj )
booljQuery.isEmptyObject( obj )1.4+
booljQuery.isFunction( obj )
booljQuery.isPlainObject( obj )1.4+