Jquery 1.1.3 Cheat Sheet

ADVERTISEMENT

Jquery 1.1.3 Cheat Sheet 2007-08-20
<
Core
Selectors
E:nth-child(n) / E:first-child / E:last-child / E:only-child
$(html) / $(element) / $(selector [,context])
$(func) / $(document).ready(func)
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
E:not(s)
does not match simple selector s
Attributes
attr(name) / attr(name,val) / attr({name:val})
attr(name, func)
E F
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"
E[@foo~=bar]
space-delimited "foo" attribute contains "bar"
next([expr])
prev([expr])
Removes matched elements from list
E[@foo=bar][@baz=bop]
Match multiple attributes
not(expr) / not(Element)
:gt(N) / :lt(N)
:eq(0) and :nth(0)
parent([expr]) / parents([expr])
children([expr])
:first / :last
:even / :odd
siblings([expr])
end()
:parent
elements which have child elements (including text).
DOM Manipulation
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
$.getJSON(url,props,fn(json) )
trigger(type, data)
Executes browser's default action also
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]
);

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go