Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Jquery 1.3.2 Cheat Sheet, Cheat Sheet of Javascript programming

All-in-one cheat sheet about the JavaScript library: Jquery 1.3.2

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

anala
anala 🇺🇸

4.3

(15)

259 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
$
(
html
)
/ $
(
element
)
/ $
(
selector
[
,context
])
$
(
func
)
=== $
(
document
)
.read
y
(
func
)
#id
/
.className :visible
/
:hidden
each
func
$("img").each(function(i){ :enabled
/
:disabled :checked
/
:selected
$
()[
i
]
=== $
()
.
g
et
(
i
)
this.src = "test" + i + ".jpg";
$
()
.len
g
th / $
()
.size
()
/ index
(
ob
j)
return false; // stop looping over each :first
/
:last :e
q
(
0
)
/
:nth
(
0
)
$().selector() / $().context() }); :header / :animated :even / :odd
E:empty has no children (including text nodes)
.data
(
ke
y)
/ .data
(
ke
y
,val
)
/ .removeDat
a
(
ke
y)
Store/retrieve/remove arbitrary data tied to elements E:not
(
s
)
does not match simple selector s
.queue(name) / .queue(name, [fn|queue]) Retrieve an element's queue or add to/replace existing queue E F F element descendant of an E element
E > FF element child of an E element
att
r
(
name
)
/ att
r
(
name,val
)
/ att
r
({
name:val
})
att
r
(
name, func
)
E+FF element immediately preceded by an E element
removeAtt
r
(
name
)
$("img").attr("title", function() { return this.src }); E~FF element preceded by an E element
E[foo] contains a "foo" attribute
E[foo=bar] "foo" attribute value is exactly equal to "bar"
E[foo^=bar] "foo" attribute value begins exactly with "bar"
add
(
ex
p
r
)
/ add
(
html
)
/ add
(
Element
)
Append more elements to the set of matched elements E
[
foo$=bar
]
"foo" attribute value ends exactly with "bar"
contains
(
'text'
)
$("div").contains('text') === $("div :contains('text')") E
[
foo*=bar
]
"foo" attribute value contains the substring "bar"
filter
(
ex
p
r
)
/ filter
(
func
)
Leave elements matching expr or func returning true E[foo!=bar] "foo" attribute is not equal to "bar"
find
(
ex
p
r
)
$("p").find("span") === $("p span") E[foo~=bar] space-delimited "foo" attribute contains "bar"
is
(
ex
p
r
[
,ex
p
r
])
Returns true if any in set matches expr. Complex selectors ok E
[
foo=bar
][
baz=bo
p]
Match multiple attributes
next
([
ex
p
r
])
/
p
re
v
(
ex
p
r
)
Only immediate next/prev sibling [if expr matches] :
p
arent elements which have child elements (including text)
nextAll
([
ex
p
r
])
/
p
revAll
(
ex
p
r
)
All next/previous siblings [if expr matches] :contains
(
'test'
)
elements which contain the specified text.
not
(
ex
p
r
)
/ not
(
Element
)
Removes matched elements from list :in
p
ut All form elements, not just type=input
parent([expr]) Immediate parent, if matches expr
parents([expr]) All parent elements matching expr
offsetParen
t
()
Positioning offset parent $.a
j
a
x
(
p
ro
p
erties
)
async: true
closes
t
(
ex
p
r
)
===
p
arents
(
ex
p
r :first
)
Find closest parent element matching expr $.ajaxSetup ( properties ) beforeSend: func(xhr)
siblings([expr]) / children([expr]) andSelf() / end() $.get ( url, properties, fn(data) ) cache: true (false=no caching
)
$.getJSON (url,props,fn(json) ) complete: func(xhr, textStatus)
before
(
content
)
/ afte
r
(
content
)
Creates a new sibling before/after element $.getScript ( url, callback ) contentType: String
insertBefore
(
ex
p
r
)
/ insertAfte
r
(
ex
p
r
)
Attach selected elements as new sibling to others $.post ( url, props, fn(data) ) data: {obj} | String
p
re
p
end
(
content
)
/ a
pp
end
(
content
)
Creates a new child node at the beginning/end ajaxComplete ( fn(xhr,props) ) dataFilter: func(data,type) - return sanitized data
p
re
p
endTo
(
ex
p
r
)
/ a
pp
endTo
(
ex
p
r
)
Attach selected elements to others, return attched ajaxError ( fn(xhr,props) ) dataType: [xml,html,script,json,jsonp,text]
em
p
t
y
()
- Removes all child nodes and conten
t
remove
()
ajaxSend ( fn(xhr,props) ) error: func(xhr, textStatus, exception)
wra
p
(
html
)
$("p").wrap("<div class='wrap'></div>"); ajaxStart ( fn(xhr,props) ) global: true (fire global events)
wra
p
All
(
html
|
elem
)
/ wra
p
Inner
(
html
|
elem
)
replaceWith(content) / replaceWith(expr) ajaxStop ( fn(xhr,props) ) ifModified: false
clone([boolean]) Clone event handlers if passed true ajaxSuccess ( fn(xhr,props) ) jsonp: String
.serialize() processData:true
css
(
name
)
-
g
et val from first element in list onl
y
css
(
ke
y
,val
)
/ css
(
{
ke
y
:val, ke
y
:val
}
)
.serializeArra
y
() scriptCharset: String
offset
()
/
p
osition
()
Returns {top,left} relative to doc or offset parent .load (url, props, fn(responseText,status,xhr) ) success: func(data, textStatus)
scrollTo
p
([
num
])
/ scrollLeft
([
num
])
Scroll position of first element only partial content using selector in url: timeout: Number
hei
g
ht
()
/ hei
g
ht
(
val
)
/ width
()
/ width
(
val
)
innerHei
g
ht
()
/ innerWidth
()
$("#feed").load("feeds.php .results", type: [POST,GET]
outerHeight( [bool] ) / outerWidth( [bool] ) Pass false to ignore margin
s
{limit: 25}, url: string
function(text,status,xhr) { alert("Loaded 25!");} username: String / password: String (for auth
)
bind (type,data,func) / unbind (type,func) function handler(event) { ); xhr: func (to create the XMLHttpRequest object
)
one (type, data, func) - execute only once alert(event.data.foo);
hover
(
overfunc, outfunc
)
}$.support.property Check for browser support of features:
to
gg
le
(
evenfunc, oddfunc
)
$("p").bind("click", {foo: "bar"}, handler)
tri
gg
er
(
t
yp
e, data
)
Executes browser's default action also
Trigger an event: event () Bind a function to an event: event(fn) $.browser.version $.browser.[safari, opera, msie, mozilla]
$.each
(
ob
j
, func
)
$.trim (str) / $.unique (array)
tri
gg
er
(
t
yp
e, data
)
Executes browser's default action also $.each( [0,1,2], function(i, n){ $.extend ( target, prop1, propN )
live
(
t
yp
e,fn
)
Handle event using event delegation alert( "Item #" + i + ": " + n ); var options = { name: "bar" };
die (type,fn) Remove events added w/ live(). }); $.extend({validate:false,name:'foo'}, options)
;
$.each( {name:"John",lang:"JS"},function(i,n)
{
Result == { validate: false, name: "bar"
}
Speeds: slow / normal / fast / #ms to
gg
le
([
boolean
])
/ to
gg
le
(
s
p
eed,fn
)
alert( "Name: " + i + ", Value: " + n ); $.map (array, func)
animate (params, options) animate
(p
arams, s
p
eed, easin
g
, callback
)
}); $.map( [0,1,2], function(n){ return n + 4; });
hide/show
(
s
p
eed
[
,callback
])
stop (clearQue,gotoEnd) $.grep ( array, func, invert) $.merge (array, array) - removes dupes
fadeIn/fadeOut
(
s
p
eed, callback
)
fadeTo (speed, opacity, callback) $.grep( [0,1,2], function(n,i){ return n>0; }) == [1,2] $.merge( [0,1,2], [2,3,4] ) === [0,1,2,3,4]
slideDown/slideU
p
(
s
p
eed, callback
)
slideTo
gg
le
(
s
p
eed,callback
)
$.makeArray (obj) === [obj] $.inArray (value, array)
$.isArray (obj) / $.isFunction (obj) $.inArray('y',['x','y','z']) == 1 (-1 if not found
)
Effects
Feature/Browser Detection
Jquery 1.3.2 Cheat Sheet 2009-05-07 by Matt Kruse http://www.JavascriptToolbox.com/jquery/cheatsheet/ Twitter:@matt_kruse Home: http://mattkruse.com
EventTypes: blur, change, click, dblclick, error, focus, keydown, keypress, keyup, load, mousedown, mouseenter,
mouseleave, mousemove, mouseout, mouseover, mouseup, resize, scroll, select, submit, unload
boxModel, cssFloat, hrefNormalized, htmlSerialize, leadingWhitespace, noCloneEvent, objectAll, opacity,
scriptEval, style, tbody
Attributes
Events (return false from handlers to cancel default action)
Misc
Data
html() / html(content) / text() / text(content) / val() / val(value)
Set jQuery.fx.off=true to disable all current and queued animations
CSS
Selectors
AJAX
Core
Traversing
DOM Manipulation
addClass(c) / hasClass(c) / removeClass(c) / toggleClass(c[,switch])
Types= :password :radio :checkbox :submit :image :reset :button :file
:nth-child(n) / :first-child / :last-child / :only-child / :gt(n) / :lt(n)

Partial preview of the text

Download Jquery 1.3.2 Cheat Sheet and more Cheat Sheet Javascript programming in PDF only on Docsity!

$ (html) /^ $ (element) /^ $ (selector [,context])

$ (func) ===^ $ (document). ready (func)^

#id^ /^ .className^

:visible^ /^ :hidden

each^ (func)^

$("img").each(function(i){^

:enabled^ /^ :disabled^

:checked^ /^ :selected

$ ()[i] ===^ $ (). get (i)^

this.src = "test" + i + ".jpg"; $ (). length^ /^ $ (). size ()^ /

index (obj)^

return false; // stop looping over each

:first^ /^ :last^

:eq (0)^ /^ :nth (0)

$ (). selector ()^ /^ $ () .context

()^ });

:header^ /^ :animated^

:even^ /^ :odd E :empty^

has no children (including text nodes)

.data (key) /^ .data (key,val) /

.removeData (key)^

Store/retrieve/remove arbitrary data tied to elements

E :not(s)^

does not match simple selector s

.queue (name)^ /^ .queue (name, [fn|queue])^

Retrieve an element's queue or add to/replace existing queue

E F^

F element descendant of an E element E^ >^ F^

F element child of an E element

attr (name) /^ attr (name,val) /

attr ({name:val})^

attr (name, func)^

E^ +^ F^

F element immediately preceded by an E element

removeAttr (name)^

$("img").attr("title", function() { return this.src });

E^ ~^ F

F element preceded by an E element E [foo]^

contains a "foo" attribute E [foo=bar]^

"foo" attribute value is exactly equal to "bar" E [foo^=bar]^

"foo" attribute value begins exactly with "bar"

add (expr)^ /^ add (html)^ /^ add (Element)^

Append more elements to the set of matched elements

E [foo$=bar]^

"foo" attribute value ends exactly with "bar"

contains ('text')^

$("div").contains('text') === $("div :contains('text')")

E [foo=bar]*

"foo" attribute value contains the substring "bar"

filter (expr)^ /^ filter (func)^

Leave elements matching expr or func returning true

E [foo!=bar]

"foo" attribute is not equal to "bar"

find (expr)^

$("p").find("span") === $("p span")

E [foo~=bar]^

space-delimited "foo" attribute contains "bar"

is (expr [,expr])^

Returns true if any in set matches expr. Complex selectors ok

E [foo=bar][baz=bop]

Match multiple attributes

next ([expr])^ /^ prev (expr)

Only immediate next/prev sibling [if expr matches]

:parent^

elements which have child elements (including text)

nextAll ([expr])^ /^ prevAll

(expr)^

All next/previous siblings [if expr matches]

:contains

('test')^

elements which contain the specified text.

not (expr)^ /^ not (Element)

Removes matched elements from list

:input^

All form elements, not just type=input

parent ([expr])^

Immediate parent, if matches expr parents ([expr])^

All parent elements matching expr offsetParent ()^

Positioning offset parent^

$.ajax (^ properties )^

async: true

closest (expr) ===^ parents

(expr :first)^

Find closest parent element matching expr

$.ajaxSetup

( properties )^

beforeSend: func(xhr)

siblings ([expr])^ /^ children

([expr])^ andSelf

()^ /^ end ()^

$.get^ ( url, properties, fn(data) )

cache: true (false=no caching) $.getJSON^ (url,props,fn(json) )

complete: func(xhr, textStatus)

before (content)^ /^ after (content)

Creates a new sibling before/after element

$.getScript

( url, callback )^

contentType: String

insertBefore (expr)^ /^ insertAfter

(expr)^ Attach selected elements as new sibling to others

$.post^ ( url, props, fn(data) )

data: {obj} | String

prepend (content)^ /^ append

(content)^ Creates a new child node at the beginning/end

ajaxComplete

( fn(xhr,props) )^

dataFilter: func(data,type) - return sanitized data

prependTo (expr)^ /^ appendTo

(expr)^ Attach selected elements to others, return attched

ajaxError^

( fn(xhr,props) )^

dataType: [xml,html,script,json,jsonp,text]

empty ()^ - Removes all child nodes and content

remove ()^

ajaxSend^ ( fn(xhr,props) )

error: func(xhr, textStatus, exception)

wrap (html)^

$("p").wrap("

");

ajaxStart

( fn(xhr,props) )^

global: true (fire global events)

wrapAll (html|elem)^ /^ wrapInner

(html|elem)^ replaceWith

(content)^ /^ replaceWith (expr)^

ajaxStop^ ( fn(xhr,props) )^

ifModified: false

clone ([boolean])^

Clone event handlers if passed true

ajaxSuccess^ ( fn(xhr,props) )

jsonp: String .serialize ()^

processData:true

css (name) - get val from first element in list only

css (key,val)^ /^ css

(^ {key:val, key:val} )^

.serializeArray ()^

scriptCharset: String

offset ()^ /^ position ()^

Returns {top,left} relative to doc or offset parent

.load^ (url, props, fn(responseText,status,xhr) )

success: func(data, textStatus)

scrollTop ([num])^ /^ scrollLeft

([num])^ Scroll position of first element only

partial content using selector in url:

timeout: Number

height ()^ /^ height (val)^ /

width ()^ /^ width (val)^

innerHeight ()^ /^ innerWidth

()^

$("#feed").load("feeds.php .results",

type: [POST,GET]

outerHeight ( [bool] )^ /^ outerWidth

( [bool] )^ Pass false to ignore margins

{limit: 25},^

url: string function(text,status,xhr) { alert("Loaded 25!");}

username: String / password: String (for auth)

bind^ (type,data,func)^ /^ unbind

(type,func)^ function handler(event) {

);^

xhr: func (to create the XMLHttpRequest object)

one^ (type, data, func) - execute only once

alert(event.data.foo); hover^ (overfunc, outfunc)^

}^

$.support. property^

Check for browser support of features:

toggle^ (evenfunc, oddfunc)

$("p").bind("click", {foo: "bar"}, handler) trigger^ (type, data)^

Executes browser's default action also Trigger an event:^ event^ ()^

Bind a function to an event:

event^ (fn)^

$.browser.version^

$.browser .[safari, opera, msie, mozilla] $.each^ (obj, func)^

$.trim^ (str)^ /^ $.unique^ (array)

trigger^ (type, data)^

Executes browser's default action also

$.each( [0,1,2], function(i, n){

$.extend

( target, prop1, propN )

live^ (type,fn)^

Handle event using event delegation

alert( "Item #" + i + ": " + n );

var options = { name: "bar" };

die^ (type,fn)^

Remove events added w/ live().

});^

$.extend({validate:false,name:'foo'}, options); $.each( {name:"John",lang:"JS"},function(i,n){

Result == { validate: false, name: "bar" }

Speeds: slow / normal / fast / #ms

toggle

([boolean])^ /^ toggle^ (speed,fn)

alert( "Name: " + i + ", Value: " + n );

$.map^ (array, func)

animate^ (params, options)

animate^ (params, speed, easing, callback)

});^

$.map( [0,1,2], function(n){ return n + 4; });

hide / show^ (speed [,callback])

stop (clearQue,gotoEnd)^

$.grep^ ( array, func, invert)

$.merge^ (array, array) - removes dupes

fadeIn / fadeOut^ (speed, callback)

fadeTo (speed, opacity, callback)

$.grep( [0,1,2], function(n,i){ return n>0; }) == [1,2]

$.merge( [0,1,2], [2,3,4] ) === [0,1,2,3,4]

slideDown / slideUp^ (speed, callback)

slideToggle

(speed,callback)^

$.makeArray^ (obj) === [obj]

$.inArray^ (value, array) $.isArray^ (obj)^ /^ $.isFunction

(obj)^ $.inArray('y',['x','y','z']) == 1 (-1 if not found)

Effects

Feature/Browser Detection

Jquery 1.3.2 Cheat Sheet

2009-05-07^ by Matt Kruse

http://www.JavascriptToolbox.com/jquery/cheatsheet/

Twitter:@matt_kruse

Home: http://mattkruse.com

EventTypes:^ blur, change, click, dblclick, error, focus, keydown, keypress, keyup, load, mousedown, mouseenter,mouseleave, mousemove, mouseout, mouseover, mouseup, resize, scroll, select, submit, unload

boxModel, cssFloat, hrefNormalized, htmlSerialize, leadingWhitespace, noCloneEvent, objectAll, opacity,scriptEval, style, tbody Attributes Events (return false from handlers to cancel default action)

Misc

Data html ()^ /^ html (content)^

/^ text ()^ /^ text (content)^

/^ val ()^ /^ val (value) Set^ jQuery.fx.off =true to disable all current and queued animations

CSS

Selectors AJAX

Core Traversing DOM Manipulation addClass (c)^ /^ hasClass

(c)^ /^ removeClass (c)^ / toggleClass (c[,switch])

:nth-child (n)^ /^ :first-child Types=^ :password :radio :checkbox :submit :image :reset :button :file

/^ :last-child^ /^ :only-child

/^ :gt (n)^ /^ :lt (n)