SlideShare a Scribd company logo
1 of 44
Download to read offline
`




Thursday, February 28, 2013
Want to keep up with
                                best practices?




Thursday, February 28, 2013
Want to make your site pop
                                 with               ?




Thursday, February 28, 2013
Want to make your site pop
                                 with fancy effects ?




Thursday, February 28, 2013
Want to check if Javascript is enabled?




Thursday, February 28, 2013
Want to add neat hover states?




Thursday, February 28, 2013
Want to safely run your code when
                            the page is loaded?




Thursday, February 28, 2013
Don’t want to use that pesky CSS?




Thursday, February 28, 2013
Don’t want to use boring
                                vanilla Javascript?




Thursday, February 28, 2013
Just use                           !
                              You know when you’re doing it right when you’re loading 12 jQuery plugins.




Thursday, February 28, 2013
JQuery

Thursday, February 28, 2013
• BASICS : Manipulating the DOM
                    • EVENTS
                    • EFFECTS
                    • AJAX : Processing in the Background


Thursday, February 28, 2013
JQuery
                         javascript library designed to simplify client sidescripting




Thursday, February 28, 2013
How to Use JQuery
                    •         include jQuery library




                     •        write your SCRIPTS !!!



Thursday, February 28, 2013
Querying the DOM
                       searching the DOM for the elements or objects


                               $([selectors])                $(‘li’);
                                       [selectors] can be

                                       id - ex. #container
                                         class - ex. .list
                                         element - ex. li




Thursday, February 28, 2013
.find()                  .children()
                 get the descendant of   get the children of each
                 each element            element

                 syntax:                 syntax:
                 $(‘.list’).find(‘li’);   $(‘.list’).children(‘li’);




Thursday, February 28, 2013
.parents()                     .parent()
         get the ancestors of each      get the parent of each
         element                        element

         syntax:                        syntax:
         $(‘.current’).parents(‘ul’);   $(‘.current’).parent(‘ul’);




Thursday, February 28, 2013
.eq()                         .next()
      select an element at          get the following sibling element
      index n                       .prev()
                                    get the preceding sibling element
      syntax:
      $(‘.list’).find(‘li’).eq(2);   syntax:
                                    $(‘.list’).find(‘li’).eq(2).next();
                                    $(‘.list’).find(‘li’).eq(2).prev();




Thursday, February 28, 2013
Manipulating the DOM
                        adding new elements, modifying, removing etc.




Thursday, February 28, 2013
.addClass()                          .removeClass()
  add specified classes                 remove a single class

  syntax:                              syntax:
  $(‘.list’).children(‘li’).addClass   $(‘.current’).removeClass
  (‘red’);                             (‘current’);




Thursday, February 28, 2013
.attr()
                              return the value of an attribute

                              syntax:
                              $(‘.current’).find(‘a’).attr(‘href’);




Thursday, February 28, 2013
.before()
                              append content before an element

                              .after()
                              append content after an element

                              .append()
                              append content at the end of an
                              element




Thursday, February 28, 2013
$(‘.current’).append(‘<p>appended content</p>’);
       $(‘.list’).find(‘li’).eq(0).after(‘<li>content inserted by after</li>’);




Thursday, February 28, 2013
api.jquery.com




Thursday, February 28, 2013
JQuery
                              Events Handler


Thursday, February 28, 2013
What are Events?
                              These methods are used to register behaviors to take
                              effect when the user iteracts with the browser, and to
                              further manipulate those registered behaviors.


                              Examples:
                              • moving a mouse over an element
                              • selecting a radio button
                              • clicking on an element




Thursday, February 28, 2013
Javascript Events




Thursday, February 28, 2013
JQuery Advantage
                              ✓ All of the out-of-the-box functionality in jQuery are in
                              reality extensions.

                              ✓ This includes all the shorthands, like click(), hover(),
                              toggle(), etc., but also the core-methods like bind(), each
                              (), animate(), and so on.

                              ✓ This means that you can detach functionality you are
                              not using, making the library even smaller--file-size wise,
                              as well as memory-footprint wise.

                              ✓ This is pure design-genius!




Thursday, February 28, 2013
JQuery
                          Events Category


Thursday, February 28, 2013
Event Handler Attachment




Thursday, February 28, 2013
Browser Events




Thursday, February 28, 2013
Document Loading




Thursday, February 28, 2013
Form Events




Thursday, February 28, 2013
Keyboard Events


                               Mouse Events



Thursday, February 28, 2013
api.jquery.com




Thursday, February 28, 2013
Animation
                              JQuery has built in effects

                              Examples:
                              $(h1).hide(“slow”);
                              $(h1).fadeOut(2000);
                              $(h1).slideDown(“fast”);




                              You can chain them

                              Examples:
                              $(h1).fadeOut(1000). slideDown();



Thursday, February 28, 2013
Or roll your own
                              JQuery animate()

                              Syntax:
                              $(selector).animate({params}, speed, callback);




                              Example:
                              $(“#block”).animate({
                                  width: “100px”,
                                  opacity: 0.5,
                                  fontSize: “3em”,
                                  borderWidth: “10px”
                              }, 1500);



Thursday, February 28, 2013
api.jquery.com




Thursday, February 28, 2013
AJAX    (Asynchronous Javascript and XML)


                  a technique used to send or retrieve data from a
                server in the background without interfering with the
                              current state of the page.




Thursday, February 28, 2013
JQuery AJAX
                              Syntax:
                              $.ajax(url, settings); OR SIMPLY
                              $.ajax(settings);


                              where settings is a set of key/value pairs which JQuery
                              calls PlainObject

                              e.g.
                              { key : value }




Thursday, February 28, 2013
Basic Settings


Thursday, February 28, 2013
url
                              the url to which the request is sent




                              type
                              the type of request to make

                              e.g.
                              POST, GET




                              data
                              the data to be sent to the server

                              e.g.
                              { “name” : “Juan”, “lastname” : “Dela Cruz” }
                              or
                              “name=Juan&lastname=Dela Cruz”
Thursday, February 28, 2013
dataType
                              the type of data that you are expecting back from the
                              server

                              e.g.
                              xml, json, script, html, or text




                              error
                              a function to be called if the request fails



                              success
                              a function to be called if the request succeeds



                              complete
                              a function to be called when the request finishes (only
                              executes after success and error callbacks are executed)

Thursday, February 28, 2013
api.jquery.com




Thursday, February 28, 2013

More Related Content

Similar to Jquery at-webcamp

Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScriptYnon Perek
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQueryKnoldus Inc.
 
Writing Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UIWriting Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UIYnon Perek
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxazz71
 

Similar to Jquery at-webcamp (8)

Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
 
Jquery
JqueryJquery
Jquery
 
Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
 
Writing Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UIWriting Reusable Web Components with jQuery and jQuery UI
Writing Reusable Web Components with jQuery and jQuery UI
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
 
Jquery
JqueryJquery
Jquery
 

Jquery at-webcamp

  • 2. Want to keep up with best practices? Thursday, February 28, 2013
  • 3. Want to make your site pop with ? Thursday, February 28, 2013
  • 4. Want to make your site pop with fancy effects ? Thursday, February 28, 2013
  • 5. Want to check if Javascript is enabled? Thursday, February 28, 2013
  • 6. Want to add neat hover states? Thursday, February 28, 2013
  • 7. Want to safely run your code when the page is loaded? Thursday, February 28, 2013
  • 8. Don’t want to use that pesky CSS? Thursday, February 28, 2013
  • 9. Don’t want to use boring vanilla Javascript? Thursday, February 28, 2013
  • 10. Just use ! You know when you’re doing it right when you’re loading 12 jQuery plugins. Thursday, February 28, 2013
  • 12. • BASICS : Manipulating the DOM • EVENTS • EFFECTS • AJAX : Processing in the Background Thursday, February 28, 2013
  • 13. JQuery javascript library designed to simplify client sidescripting Thursday, February 28, 2013
  • 14. How to Use JQuery • include jQuery library • write your SCRIPTS !!! Thursday, February 28, 2013
  • 15. Querying the DOM searching the DOM for the elements or objects $([selectors]) $(‘li’); [selectors] can be id - ex. #container class - ex. .list element - ex. li Thursday, February 28, 2013
  • 16. .find() .children() get the descendant of get the children of each each element element syntax: syntax: $(‘.list’).find(‘li’); $(‘.list’).children(‘li’); Thursday, February 28, 2013
  • 17. .parents() .parent() get the ancestors of each get the parent of each element element syntax: syntax: $(‘.current’).parents(‘ul’); $(‘.current’).parent(‘ul’); Thursday, February 28, 2013
  • 18. .eq() .next() select an element at get the following sibling element index n .prev() get the preceding sibling element syntax: $(‘.list’).find(‘li’).eq(2); syntax: $(‘.list’).find(‘li’).eq(2).next(); $(‘.list’).find(‘li’).eq(2).prev(); Thursday, February 28, 2013
  • 19. Manipulating the DOM adding new elements, modifying, removing etc. Thursday, February 28, 2013
  • 20. .addClass() .removeClass() add specified classes remove a single class syntax: syntax: $(‘.list’).children(‘li’).addClass $(‘.current’).removeClass (‘red’); (‘current’); Thursday, February 28, 2013
  • 21. .attr() return the value of an attribute syntax: $(‘.current’).find(‘a’).attr(‘href’); Thursday, February 28, 2013
  • 22. .before() append content before an element .after() append content after an element .append() append content at the end of an element Thursday, February 28, 2013
  • 23. $(‘.current’).append(‘<p>appended content</p>’); $(‘.list’).find(‘li’).eq(0).after(‘<li>content inserted by after</li>’); Thursday, February 28, 2013
  • 25. JQuery Events Handler Thursday, February 28, 2013
  • 26. What are Events? These methods are used to register behaviors to take effect when the user iteracts with the browser, and to further manipulate those registered behaviors. Examples: • moving a mouse over an element • selecting a radio button • clicking on an element Thursday, February 28, 2013
  • 28. JQuery Advantage ✓ All of the out-of-the-box functionality in jQuery are in reality extensions. ✓ This includes all the shorthands, like click(), hover(), toggle(), etc., but also the core-methods like bind(), each (), animate(), and so on. ✓ This means that you can detach functionality you are not using, making the library even smaller--file-size wise, as well as memory-footprint wise. ✓ This is pure design-genius! Thursday, February 28, 2013
  • 29. JQuery Events Category Thursday, February 28, 2013
  • 34. Keyboard Events Mouse Events Thursday, February 28, 2013
  • 36. Animation JQuery has built in effects Examples: $(h1).hide(“slow”); $(h1).fadeOut(2000); $(h1).slideDown(“fast”); You can chain them Examples: $(h1).fadeOut(1000). slideDown(); Thursday, February 28, 2013
  • 37. Or roll your own JQuery animate() Syntax: $(selector).animate({params}, speed, callback); Example: $(“#block”).animate({ width: “100px”, opacity: 0.5, fontSize: “3em”, borderWidth: “10px” }, 1500); Thursday, February 28, 2013
  • 39. AJAX (Asynchronous Javascript and XML) a technique used to send or retrieve data from a server in the background without interfering with the current state of the page. Thursday, February 28, 2013
  • 40. JQuery AJAX Syntax: $.ajax(url, settings); OR SIMPLY $.ajax(settings); where settings is a set of key/value pairs which JQuery calls PlainObject e.g. { key : value } Thursday, February 28, 2013
  • 42. url the url to which the request is sent type the type of request to make e.g. POST, GET data the data to be sent to the server e.g. { “name” : “Juan”, “lastname” : “Dela Cruz” } or “name=Juan&lastname=Dela Cruz” Thursday, February 28, 2013
  • 43. dataType the type of data that you are expecting back from the server e.g. xml, json, script, html, or text error a function to be called if the request fails success a function to be called if the request succeeds complete a function to be called when the request finishes (only executes after success and error callbacks are executed) Thursday, February 28, 2013