0% found this document useful (0 votes)
48 views

JQueryCheatSheet-1 1 3

This document provides a summary of jQuery selectors, methods, and functions in 3 sentences or less: It outlines jQuery selectors for selecting elements by id, class, attributes, and more. It also summarizes common jQuery methods for manipulating the DOM, handling events, and AJAX requests. Finally, it lists utility functions for traversing, manipulating, and extending objects and arrays.

Uploaded by

cewo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

JQueryCheatSheet-1 1 3

This document provides a summary of jQuery selectors, methods, and functions in 3 sentences or less: It outlines jQuery selectors for selecting elements by id, class, attributes, and more. It also summarizes common jQuery methods for manipulating the DOM, handling events, and AJAX requests. Finally, it lists utility functions for traversing, manipulating, and extending objects and arrays.

Uploaded by

cewo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Jquery 1.1.3 Cheat Sheet 2007-08-20 <http://www.JavascriptToolbox.

com/jquery/>
Core Selectors
$(html) / $(element) / $(selector [,context]) $(func) / $(document).ready(func) E:nth-child(n) / E:first-child / E:last-child / E:only-child
each (func) $("img").each(function(i){ E:empty has no children (including text nodes)
$()[i] o/$().get(i) this.src = "test" + i + ".jpg"; E:enabled E:disabled
$().length / $().size() return false; // stop looping over each E:checked E:selected
}); E#id E.className
Attributes E:not(s) does not match simple selector s
attr(name) / attr(name,val) / attr({name:val}) attr(name, func) EF F element descendant of an E element
removeAttr(name) $("img").attr("title", function() { return this.src }); E>F F element child of an E element
addClass(c) / removeClass(c) / toggleClass(c) E+F F element immediately preceded by an E element
html() / html(content) text() / text(content) E~F F element preceded by an E element
Traversing E[@foo] contains a "foo" attribute
add(expr) / add(html) / add(Element) Add more elements to the set of matched elements E[@foo=bar] "foo" attribute value is exactly equal to "bar"
contains(text) Leave only elements that contain 'text' E[@foo^=bar] "foo" attribute value begins exactly with "bar"
filter(expr) / filter(func) Leave elements matching expr or func returning true E[@foo$=bar] "foo" attribute value ends exactly with "bar"
find(expr) $("p").find("span") === $("p span") E[@foo*=bar] "foo" attribute value contains the substring "bar"
is(expr [,expr]) returns boolean E[@foo!=bar] "foo" attribute is not equal to "bar"
next([expr]) prev([expr]) E[@foo~=bar] space-delimited "foo" attribute contains "bar"
not(expr) / not(Element) Removes matched elements from list E[@foo=bar][@baz=bop] Match multiple attributes
parent([expr]) / parents([expr]) children([expr]) :gt(N) / :lt(N) :eq(0) and :nth(0)
siblings([expr]) end() :first / :last :even / :odd
DOM Manipulation :parent elements which have child elements (including text).
before(content) / after(content) Creates a new sibling before/after element :contains('test') elements which contain the specified text.
prepend(content) / append(content) Creates a new child node at the beginning/end :visible / :hidden
clone([deep]) remove() :input All form elements, not just type=input
empty() Removes all child nodes and content from E Input Type Selectors:
wrap(html) $("p").wrap("<div class='wrap'></div>"); :password :radio :checkbox :submit :image :reset :button :file
CSS Effects
css(name) get val from first element in list only Speed Values: slow / normal / fast / #ms
css(key,val) / css( {key:val} ) height() / height(val) / width() / width(val) animate(params, speed, easing, callback)
Events - return false from handlers to cancel default action fadeIn/fadeOut(speed, callback) fadeTo(speed, opacity, callback)
bind(type,data,func) / unbind(type,func) function handler(event) { hide/show(speed, callback) slideDown/slideUp(speed, callback)
one(type, data, func) - execute only once alert(event.data.foo); toggle() slideToggle(speed,callback)
hover(overfunc, outfunc) } AJAX
Event Types: $("p").bind("click", {foo: "bar"}, handler) $.ajax( properties ) async: boolean
blur, change, click, dblclick, error, focus, keydown, keypress, keyup, load, mousedown, mousemove, $.ajaxSetup ( properties ) beforeSend: func
mouseout, mouseover, mouseup, ready, resize, scroll, select, submit, unload $.get( url, properties, fn(data) ) complete: func
toggle(evenfunc, oddfunc) $.getIfModified(url,props,fn(data) ) contentType: string
trigger(type, data) Executes browser's default action also $.getJSON(url,props,fn(json) ) data: {obj}/String
Misc $.getScript( url, callback ) dataType: [xml,html,script,json]
$.browser.[safari, opera, msie, mozilla] $.browser.version $.post( url, props, fn(data) ) error: func
$.each (obj, func) $.trim(str) - Trim a string ajaxComplete( fn(xhr,props) ) global: boolean
$.each( [0,1,2], function(i, n){ $.extend ( target, prop1, propN ) ajaxError( fn(xhr,props) ) ifModified: boolean
alert( "Item #" + i + ": " + n ); var settings = { validate: false, limit: 5, name: "foo" }; ajaxSend( fn(xhr,props) ) processData:boolean
}); var options = { validate: true, name: "bar" }; ajaxStart( fn(xhr,props) ) success: func
$.each( { name:"John",lang:"JS" },function(i,n){ jQuery.extend(settings, options); ajaxStop( fn(xhr,props) ) timeout: number
alert( "Name: " + i + ", Value: " + n ); settings == { validate: true, limit: 5, name: "bar" } ajaxSuccess( fn(xhr,props) ) type: [POST,GET]
}); $.map (array, func) serialize() url: string
$.grep( array, func, invert) $.map( [0,1,2], function(n){ load/loadIfModified( url, props, fn(responseText, status, response) )
$.grep( [0,1,2], function(n,i){ return n + 4; $("#feeds").load("feeds.php",
return n > 0; }); {limit: 25},
}); $.merge (array, array) - removes dupes function() { alert("The last 25 entries in the feed have been loaded"); }
Result = [1, 2] $.merge( [0,1,2], [2,3,4] ) === [0,1,2,3,4] );

You might also like