Upload
gaplabs
View
341
Download
0
Tags:
Embed Size (px)
Citation preview
`
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 DOMsearching the DOM for the elements or objects
$([selectors]) $(‘li’);
[selectors] can be
id - ex. #containerclass - ex. .listelement - ex. li
Thursday, February 28, 2013
.find()get the descendant of each element
syntax:
$(‘.list’).find(‘li’);
.children()get the children of each element
syntax:
$(‘.list’).children(‘li’);
Thursday, February 28, 2013
.parents()get the ancestors of each element
syntax:
$(‘.current’).parents(‘ul’);
.parent()get the parent of each element
syntax:
$(‘.current’).parent(‘ul’);
Thursday, February 28, 2013
.eq()select an element at index n
syntax:
$(‘.list’).find(‘li’).eq(2);
.next()get the following sibling element
.prev()get the preceding sibling element
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()add specified classes
syntax:
$(‘.list’).children(‘li’).addClass(‘red’);
.removeClass()remove a single class
syntax:
$(‘.current’).removeClass(‘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
JQueryEvents 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
JQueryEvents 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
JQuery has built in effects
Examples:$(h1).hide(“slow”);$(h1).fadeOut(2000);$(h1).slideDown(“fast”);
You can chain them
Examples:$(h1).fadeOut(1000). slideDown();
Animation
Thursday, February 28, 2013
JQuery animate()
Syntax:$(selector).animate({params}, speed, callback);
Example:$(“#block”).animate({ width: “100px”, opacity: 0.5, fontSize: “3em”, borderWidth: “10px”}, 1500);
Or roll your own
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 AJAXSyntax:$.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
urlthe url to which the request is sent
typethe type of request to make
e.g.POST, GET
datathe data to be sent to the server
e.g.{ “name” : “Juan”, “lastname” : “Dela Cruz” }or“name=Juan&lastname=Dela Cruz”
Thursday, February 28, 2013
dataTypethe type of data that you are expecting back from the server
e.g.xml, json, script, html, or text
errora function to be called if the request fails
successa function to be called if the request succeeds
completea 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