JQuery CheatSheet
JQuery CheatSheet
JQuery features
window.$=window.jquery=jquery=$
$(document).ready()
ready function takes arguments...Callback function..Called once when document is
ready..
$(document).ready(function(){
});
----------------------------------------------------------------------------------
JQUERY Selectors
-----------------------------------------------------------------------------
$(selector expressions,context)
specify -----> specify patteren match elemen-----Jquery Selectors uses CSS selector
paateren ...As well as it's pattern ..match elements.
$('p').append("This is paragraph.");
$('div').append("This is div");
$("#myDiv")
-----------------------------------------------------------------------------------
-----
JQUERY METHODS:::
-----------------------------------------------
JQuery Selectors Find DOM Elements---Wrap Them JQuery Object
Javascript....Return DOM object...$("#id") will return JQuery Objct..
...We Call Jquery Method ....of jquery obj...Return By JQuery Slector.
Utilities..
----------------------------------
Dom Manipulation Methods:
Jquery provide various methods .....Add edit delete lements .. in html page
Methods
append()...insert content... to the end element...specified by selector.
before() ...insert content before element.. which is specified by selectors.
after() ...insert content after element...specified by selector...
prepend...insert content ...begining of element..
remove...remove element from dom..
replaceAll... replace target element specified element.
wrap() ..wrap html structure....around each element..
$('div').append("<p>This is apppend</p>");
$('div').before("This is before");
$('div').after('This is after');
-----------------------------------------------------
Attribute Manipulations
----------------------------------------------------------
------------------------------------------------------
Dimensions Manipulations::
=------------------------------
..............................................
Traversing DOM Elements Using Jquery
include various methods traverse elements in Dom
-----------------------------------------------------------
CSS Manipulation:
various juquery methods .....manipulate ...style properties..class of Dom elements
css....style properties..get or set
addClass: addclasses to specified elements
hasClass:determine whether have give class or not..
remove class:remove single or multiple classes from specified element
toggleClass...toggle b/w adding or removing classes
..........................................
Jquer animations
..................................
.....Jquery Animations....
Include methods ..show,hide,fade in and fade out element
special effect methods..useful for building interactive webpages
animate()...Perform custom animations using..elements style property...
queue(),..show or manipulate queue of functions on specified element
stop()...stop currently running animations..
fadeIn().. display ..specified element by opaque
fadeout()..display ...specified element by making transparent..
fadeTo()...adjust opacity
fadeToggle()display or hide specified element...by animating their opacity..
hide() hide specified element..
show(); display specified element
toggle() hide visible and show unvisiblee
slideUp()display specified element..with sliding motion up
slidedown() display or hide element.
..with sliding mothion
get specified element.call animate method with json objct for style
properties,speed of animation and other options,
Apply Animation....
$('#myDiv').animate({
height:'200px',
width:'200px'
});
$('#myDiv').animate({
height:'200px',
width:'200px'
},500);
.................................................................
JQuery events:
when user click button...click event triggers...click event handler saveData..
$("#saveBtn").click(function(eventObj){
})
jquery passes event obj to every event handler function.. the event oject includes
important properties, and methods...for cross
browser...target,pageX,pageY,relatedTarget...
use mouse hover insteat of enter ...mouseenter and mouseleave events separately..
internally all methods uses on ....on() gives you more flexibility in event
binding...
on(types,selector,data,fn)
types======> one or more optional...space separated eventtypes.
data===> data to be passed to event handler... when events triggred..
fn..... a function to execute... when event is triggred...
you can also use ...filter descendants of selected elements... that trigger the
event...
$('#myDiv').on('click',':button',function(){
alert('button is clicked');
Binding multiple events....
Separated by spaces..... ,, .on(' mouseleave mouseenter',function(){
})
})
Specify named functions using event handler....
write separate function... use that for handler...use want to use same handle for
different events..or events on different element...
jQuery on() method is replace or live() or delegate()..
-------------------------------------------------
Event bubling:-
events bubbles...upto document level in dom hirarchy....till it finds it's//
--------------------------------------------------------------
jQuery ajax()
provide core functionality of ajax using... jquery...$.ajax()....sends http request
to server...
$.ajax(url)
$.ajax(url,[options])
----->url string to which submit or retrieve data...
......>options...configuration options for ajax request...options specified using
json..
this is optional..
...list of options use to configure ajax method...
accept..type of response..
async.. bydefaut all request are synchoronous... but if you set it false then this
is synchronous..
beforesend....callbackfunction executed before ajax request is send...
cache.. indicating browser cache...bydefault it is true..
complete.. callbackfunction executed when req finishes.
contentType..Type of content....
crossDomain... boolean value..indicating whether request cross domain or not..
data...data type send to the server..can be json objct,string, or array..
dataType..dataType you are expecting back from server..
error.. callbackfunction when request is fail..
global..boolean whether trigger global ajax request handler or not by default true.
headers. additional key/value pairs send with request..
isModified..default false....request is successfull only if response is changed..
since last request..This check by only last modified header..
isLocal...allow current environment to be recongnize as local..
jsonp... override the callback function name in jsonprequest..used this value
instead of callback in the callback=? part of query string in url..
jsonpCallback...string containing the callback function name for a JSonp request..
mimeType...string mimetype override mime type XMLHttpRequestmimeType....
$.ajax() sent asynchoronous http request..to submit or retrieve data from server
without reloading page
$.ajax() used to send http get,put ,delete request... it can retrieve any type of
response...
use option parameter to customize ajax request...
...................................................
jQuery get() Methods..get method sends async http get reques to the server...and
retrieve data..
$.get(url,[data],[callback]);
url---url from which you want to get data..
data..sent data to server with http request as query string.
callback().... function to be executed whend request succesds
................................................