') // create element
html(), text() // get/set html/text
remove() // removes element from DOM
append(), prepend() // insert specified content to the end/beginning of element
after(), before() // insert content after/before element
height(), width() // get/set value
clone() // create a deep copy of an element
wrap() // wrap element with another element
detach() // same as remove but keeps all jQuery related data
```
---
##Animation
```javascript
hide(), show(), toggle()
fadeOut(), fadeIn(), fadeToggle()
slideOut(), slideDown(), slideToggle()
```
Note: all of these methods accept configurations, e.g {duration: 500}
animate() - animates given css properties.
Note: in most cases it is wiser to use css animations as those are much faster
---
##Events
###Event Handlers
on(), off(), one(), trigger(), triggerHandler()
###Form Events
focus(), blur(), change(), select(), submit()
###Keyboard Events
keydown(), keyup(), keypress()
---
##Events
###Mouse Events
click(), dblclick(), hover()
###Event Object
event.preventDefault(), event.stopPropagation(), event.target
Note: some events can be used as both handlers and triggers
$('input').focus(handler) -> attaches handler onFocus
$('input').focus() -> sets focus on input
---
##Ajax
###Basic usage
```javascript
$.ajax({
type: 'POST',
url: 'authorization.php',
data: { login: 'John', password: 'gfhjkm' },
success: onSuccess,
error: onError,
complete: onComplete
});
```
###Shorthand methods
```javascript
$.get(), $.post()
$.getJSON(), $.getScript()
```
---
##Utilities
```javascript
$.each() // generic iterator function
$.extend() // merge the content of second+ objects into first one
$.trim() // remove whitespace from the beginning and end of a string
$.isArray(), $.isEmptyObject(), $.isFunction(), $.isNumeric()
$.parseHTML(), $.parseJSON()
```
---
##jQuery Plugins
One of the reasons jQuery gained so much popularity is the ease of creating plugins.
Which led to a huge collection of available plugins.
As a tradeoff, lots of those plugins are poorly coded and rarely properly maintained.
```javascript
$.fn.paintMe = function(color){
this.css('background', color);
return this;
}
$('p').paintMe('red').text('ima red!!');
```
---
##jQuery does everything !!1!
[

](http://www.doxdesk.com/img/updates/20091116-so-large.gif)
---
##Namespacing
window Global variables are evil! window.jQuery / window.$
to avoid conflict with other JavaScript Frameworks
```javascript
jQuery.noConflict();
jQuery( document ).ready(function($) {
// Code that uses jQuery's $ can follow here.
});
// Code that uses other library's $ can follow here.
```
---
##Let's make a quiz
http://www.w3schools.com/quiztest/quiztest.asp?qtest=jQuery
---
## Deffered
A factory function that returns a chainable utility object with methods to
register multiple callbacks into callback queues, invoke callback queues,
and relay the success or failure state of any synchronous or asynchronous function.
The jQuery.Deferred() factory creates a new deferred object.
```javascript
var moneyBoxForMyLoverForStValentinsDay = jQuery.Deferred();
// Don't give such names for variables if just no holiday outside
var afterStValentinsDay = moneyBoxForMyLoverForStValentinsDay.then(takeHalfToFixCar);
function takeHalfToFixCar(value) { return value / 2 }
// Imagine you save 1000uah and wait to the St. Valentines day
setTimeout(function() {
moneyBoxForMyLoverForStValentinsDay.resolve(1000);
}, 3650);
afterStValentinsDay.done(function(finalAmount) {
console.log('Honey I\'ve bought you flowers for ' + finalAmount + ' uah) I love you')
});
```
---
##Deferred methods
```javascript
deferred.then(),
deferred.always(),
deferred.done(),
deferred.fail(),
deferred.resolve(),
deferred.reject()
```
---
##jQuery Promises
Promise is an object to observe when all actions of a certain type bound to the collection, queued or not, have finished. All ajax requests return promices
```javascript
$( "button" ).on( "click", function() {
$( "p" ).append( "Started..." );
$( "div" ).each(function( i ) {
$( this ).fadeIn().fadeOut( 1000 * ( i + 1 ) );
});
$( "div" ).promise().done(function() {
$( "p" ).append( " Finished! " );
});
});
```
---
##jQuery Promises
```javascript
var effect = function() {
return $( "div" ).fadeIn( 800 ).delay( 1200 ).fadeOut();
};
$( "button" ).on( "click", function() {
$( "p" ).append( " Started... " );
$.when( effect() ).done(function() {
$( "p" ).append( " Finished! " );
});
});
```
---
##Resources
- https://oscarotero.com/jquery/
- http://learn.jquery.com/plugins/basic-plugin-creation/
- http://try.jquery.com/
- http://james.padolsey.com/jquery/#v=2.0.3&fn=
- http://blog.garstasio.com/you-dont-need-jquery/
- http://zeptojs.com/