45
Rupesh Kumar Tiwari June, 2011 BASICS OF JQUERY THE WRITE LESS, DO MORE JAVASCRIPT LIBRARY

Basics of j query

  • Upload
    roopkt

  • View
    950

  • Download
    3

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Basics of j query

Rupesh Kumar Tiwari

June, 2011

BASICS OF JQUERYTHE WRITE LESS, DO MORE JAVASCRIPT LIBRARY

Page 2: Basics of j query

AGENDA

• jQuery Basics

• Plugins

• Advanced jQuery

Page 3: Basics of j query

• $(CSS Selector)

• $(HTML)

• $(DOM element)

$

jQuery Basics…

Page 4: Basics of j query

Demo

jQuery Basics…

Page 5: Basics of j query

• $(something).action();

$

jQuery Basics…

Page 6: Basics of j query

$:Basic actions

jQuery Basics…

Page 7: Basics of j query

$:Traversal

• .children()

• .children(expression)

• .parent()

• .parent(expression)

• .find(expression)

• .filter(expression)

• .filter(function)

• eq(index)

• .not(expression)

• .add(expression)

• .next()

• .nextAll()

• .prev()

• .prevAll()

• .slice(start,end)

• .siblings()

jQuery Basics…

Page 8: Basics of j query

$:Traversal

• .end()

jQuery Basics…

Page 9: Basics of j query

Demo

jQuery Basics…

Page 10: Basics of j query

$:Manipulation

• .html(val)

• .text(val)

• .append(content)

• .appendTo(expression)

• .appendTo(jQuery object)

• .prepend(content)

• .prependTo(expression)

• .prependTo(jQuery object)

• .after(content)

• .before(content)

• .wrap(html)

• .empty()

• .remove()

• .remove(expression)

jQuery Basics…

Page 11: Basics of j query

Demo

jQuery Basics…

Page 12: Basics of j query

Selectors

• #id

• .class

• .elementType

• :first

• :last

• :not(expression)

• .parent > child

• :even

• :odd

• :contains(text)

• :empty

• :hidden

• :vissible

• [attribute]

• [attribute=value]

• [attribute!=value]

jQuery Basics…

Page 13: Basics of j query

Demo

jQuery Basics…

Page 14: Basics of j query

$:Attributes & CSS

• .attr(name,value)

• .attr(name,function)

• .attr(properties)

• .removeAttr(name)

• .val(val)

• .css(name,value)

• css(properties)

• .addClass(class)

• .removeClass(class)

jQuery Basics…

Page 15: Basics of j query

Demo

jQuery Basics…

Page 16: Basics of j query

jQuery Basics…

$:Just a few more

• .html()

• .text()

• .val()

• .attr(name)

• .css(name)

• .height()

• .width()

• .is(expression)

• .hasClass(class)

• .offset()

Page 17: Basics of j query

Demo

Page 18: Basics of j query

Speed + Not much code + pretty code + Fun

jQuery Basics…

Chaining

Page 19: Basics of j query

$(CSS Selector).action1().action2();

jQuery Basics…

Attaching multiple functions to a single selector

Page 20: Basics of j query

How to respond to user interaction

jQuery Basics…

Bindings

Page 21: Basics of j query

jQuery Basics…

Events

• click

• mouseover

• mouseout

• mouseenter

• mouseleave

• blur

• change

• dblclick

• focus

• keydown

• keyup

• keypress

• scroll

• resize

• load

• ready

Page 22: Basics of j query

Demo

jQuery Basics…

Page 23: Basics of j query

jQuery Basics…

• $(expression).function();

• $(expression).function(speed);

• $(expression).function(speed,callback);

Effects

Page 24: Basics of j query

jQuery Basics…

Effects

• show

• hide

• toggle

• slideUp

• slideDown

• slideToggle

• fadeIn

• fadeOut

• fadeTo

• scroll

• resize

• load

• ready

Page 25: Basics of j query

Demo

jQuery Basics…

Page 26: Basics of j query

If you need that little extra something

jQuery Basics…

Advanced animations

Page 27: Basics of j query

jQuery Basics…

.animate(params,duration,easing,callback)

Page 28: Basics of j query

Demo

jQuery Basics…

Page 29: Basics of j query

Want to be buzzword compliant, don’t you?

jQuery Basics…

AJAX

Page 30: Basics of j query

jQuery Basics…

• $(CSS Selector).load(url, data, callback);

• $.post(url, data, callback);

• $.get(url, data, callback)

AJAX

Page 31: Basics of j query

jQuery Basics…

$.ajax - options

• data

• type

• url

Page 32: Basics of j query

jQuery Basics…

AJAX events (global)

$(CSS selector).bind(‘globalAjaxEvent’,…);

Page 33: Basics of j query

jQuery Basics…

• ajaxStart

• ajaxSend

• ajaxSuccess

• ajaxError

AJAX events (global)

Page 34: Basics of j query

jQuery Basics…

$.ajax({

enventName:function(){

}

});

AJAX events (local)

Page 35: Basics of j query

jQuery Basics…

AJAX events (local)

• beforeSend

• success

• error

• complete

Page 36: Basics of j query

Demo

jQuery Basics…

Page 37: Basics of j query

If you think jQuery should do more, this part is for you

Plugins

Plugins

Page 38: Basics of j query

How to build Plugins

• Extend jQuery.fn

• jQuery.fn.myPlugin = function(){ … };

• $( … ).myPlugin();

Plugins…

Page 39: Basics of j query

The magical plugin helper

.each(function)

Plugins…

Page 40: Basics of j query

jQuery.fn.myPlugin = function () {

return $(this).each(function(){

//Do stuff with $(this) here

});

}

The typical plugin

Plugins…

Page 41: Basics of j query

Advanced jQuery

Now have I left you wondering how all this near stuff works?

Sorry for leaving you hanging – I’ll answer that right now..

Advanced jQuery

Page 42: Basics of j query

The Stack

Advanced jQuery…

Page 43: Basics of j query

Advanced Scripting

Advanced jQuery…

• $.getScript(url, callback)

• $.getJSON(url, data, callback)

Page 44: Basics of j query

Resources

• http://jquery.com/

• http://visualjquery.com/

• Book: jQuery in Action

Page 45: Basics of j query

Thank You

[email protected]

• Tweeter: @roopkt

• http://Rupesht.wordpress.com