220 likes | 308 Views
JQuery. Mobile Development Series, part 2. Overview. Who, What , When, Where & Why?. An open source JavaScript library that simplifies the interaction between HTML and JavaScript. Created by John Resig in 2005, released in January of 2006.
E N D
JQuery Mobile Development Series, part 2
Overview Who, What , When, Where & Why?
An open source JavaScript library that simplifies the interaction between HTML and JavaScript. • Created by John Resig in 2005, released in January of 2006. • Built in an attempt to simplify the existing DOM APIs and abstract away cross-browser issues. Who, What, When?
IE 6+ • Firefox 2+ • Safari 3+ • Chrome • Opera 9+ Where
Uses CSS to layer functionality. • Easy to separate behavior. • Quick, terse, syntax. Why?
How to Use it Find Stuff. Do Stuff.
$("div").addClass("special"); • Find some elements. • Do something with them Focus
$("div").addClass("special"); • $ is the jQuery Object (also named jQuery) • "div" finds some elements using CSS selectors • $("div") returns a jQuery set (containing 0 to many objects – divs in this case). • addClass(...) modifies all the divs Simple Syntax
$(document).ready(function(){ // Your jQuery code goes in here});$(document).ready(function(){ // Your jQuery code goes in here}); • In order to traverse and manipulate the page we must wait until it's ready to be used. • jQuery has a ready event that fires the instant the DOM is ready to be worked with. • Stick all your jQuery code in a ready block, load it unobtrusively. Getting Ready
Just to name a few: • .parent() • .next() • .prev() • .children() • .siblings() http://api.jquery.com/category/traversing/ Traversal
You can have multiple actions against a single set of elements. • Every jQuery method returns the jQuery set, for further actions (unless a value is returned). $("div").hide(); $("div").hide().css("color","blue");$("div").hide().css("color","blue").remove(); Chaining
.submit • .click • .hover • .scroll • .select http://api.jquery.com/category/events/ Events
.animate • .hide • .show • .slideToggle http://api.jquery.com/category/effects/ Effects
$('#b').load('article.html #target'); AJAX & XML
$.getJSON("file.js", function( obj ) { for ( varpropinobj ) { $("ul").append( "<li>" + prop + ": " + obj[prop] + "</li>"); } });$.getJSON("file.js", function( obj ) { for ( varpropinobj ) { $("ul").append( "<li>" + prop + ": " + obj[prop] + "</li>"); } }); AJAX & JSON
<script src='http://code.jquery.com/jquery.js'></script> • jQuery, Google, and Microsoft all host jQuery on their CDNs. • Automatically minified, gzipped, and geopositioned for performance. • Specify version to maintain deprecated functions CDN
Documentation & APIhttp://jquery.com/http://api.jquery.com/ • Optimization Tricks &Tipshttp://24ways.org/2011/your-jquery-now-with-less-suck/ • Online Toolshttp://jsbin.com/welcome/1/edithttp://codepen.io/http://jsfiddle.net/ErrRq/ References/More Info
Upcoming Sessions 2/27 – JSON 3/6 – JQuery Mobile https://www.facebook.com/ACEITSIG http://collaborate.extension.org/wiki/ACE_Information_Technology_SIG * *recordings posted { Sarah Johnstonsjohnston@agcenter.lsu.edu