Who Me?Jörn Zaeffererfrom CologneConsultant for maxence integration technologiesjQueryteam memberjQuery UI lead developerCo-Author jQuery Cookbook, due this month
It means nomore of thisvar tables = document.getElementsByTagName("table");for (vart = 0; t<tables.length; t++) {var rows = tables[t].getElementsByTagName("tr"); for (vari = 1; i<rows.length; i += 2) { if (!/(^|s)odd(s|$)/.test(rows[i].className)) { rows[i].className+= " odd"; } }};http://jsbin.com/esewu/edit
11.
Using jQuery wecan do thisjQuery("tabletr:nth-child(odd)").addClass("odd");
12.
Using jQuery wecan do thisjQuery("tabletr:nth-child(odd)").addClass("odd");jQuery function
13.
Using jQuery wecan do thisjQuery("tabletr:nth-child(odd)").addClass("odd");jQuery Selector (CSS expression)jQuery function
14.
Using jQuery wecan do thisjQuery("tabletr:nth-child(odd)").addClass("odd");jQuery Selector (CSS expression)jQuery functionjQuery Wrapper Set
15.
Using jQuery wecan do thisjQuery("tabletr:nth-child(odd)").addClass("odd");jQuery Selector (CSS expression)jQuery functionjQuery MethodjQuery Wrapper Set
16.
It really isthe “write less, do more” JavaScript Library!
17.
Why use jQueryHelpsus to simplify and speed up web developmentAllows us to avoid common headaches associated with browser developmentProvides a large pool of pluginsLarge and active communityTested on 50 browsers, 11 platformsIts for both coders and designers
18.
Why use jQueryover other solutionsHelps us to simplify and speed up web developmentAllows us to avoid common headaches associated with browser developmentProvides a large pool of pluginsLarge and active communityTested on 50 browsers, 11 platformsIts for both coders and designers
Concept 4. jQueryparameter typesCSS Selectors & custom CSS expressions jQuery("#nav") and jQuery(":first")HTML jQuery("<li><a href=“#”>link</a></li>")DOM ElementsjQuery(document) or jQuery(this) or jQuery(event.target)A function (shortcut for jQuery DOM ready event)jQuery(function(){}) = jQuery(document).ready(function(){})
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities
36.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery()each() map()size()lengthselectorcontextindex()get()
37.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery()each()map() size()lengthselectorcontext index()get()
38.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities<!DOCTYPE html><html><body><p>Gold</p><p>Silver</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>alert(jQuery("p").map(function() { return $(this).text();}).get());</script></body></html>http://jsbin.com/orani/edit#html
39.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities
40.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")
41.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")jQuery(":visible")
42.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")jQuery(":visible")jQuery(":radio:enabled:checked")
43.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")jQuery(":visible")jQuery(":radio:enabled:checked")jQuery("a[title]")
44.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")jQuery(":visible")jQuery(":radio:enabled:checked")jQuery("a[title]")jQuery("a[title][href='foo']")
45.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")jQuery(":visible")jQuery(":radio:enabled:checked")jQuery("a[title]")jQuery("a[title][href='foo']")jQuery("a:first[href*='foo']")
46.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")jQuery(":visible")jQuery(":radio:enabled:checked")jQuery("a[title]")jQuery("a[title][href='foo']")jQuery("a:first[href*='foo']")jQuery("#header, #footer")
47.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery("#nav li.contact")jQuery(":visible")jQuery(":radio:enabled:checked")jQuery("a[title]")jQuery("a[title][href='foo']")jQuery("a:first[href*='foo']")jQuery("#header, #footer")jQuery("#header, #footer").filter(":visible")
48.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesattr()removeAttr()addClass()hasClass()toggleClass()removeClass()val()
49.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesattr()removeAttr()addClass()hasClass()toggleClass()removeClass()val()
50.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities<!DOCTYPE html><html><body><input type="text" value="search" /><script src="jquery.js"></script><script>$("input").focus(function(){ var v = $(this).val(); $(this).val( v == this.defaultValue? "" : v);}).blur(function(){ var v = $(this).val(); $(this).val( !v ? this.defaultValue : v);});</script></body></html>http://jsbin.com/irico/edit#htmlhttp://jsbin.com/ihale/edit#html
51.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesadd()children()closest()find()next()nextAll()prev() prevAll() siblings()parent() parents() andSelf()end()eq()filter()is()not()slice()
52.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesadd()children()closest()find()next()nextAll()prev() prevAll() siblings()parent() parents() andSelf()end()eq()filter()is()not()slice()
53.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities<!DOCTYPE html><html><body><h3>Quotes</h3><div> <p>Now or never</p> <p>Because he could</p></div><script src="jquery.js"></script><script>$("h3").click(function() { $(this).next().toggle();}).next().hide();</script></body></html>http://jsbin.com/uhole/edit#html
54.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitieshtml()text()append()appendTo()prepend()prependTo()after()insertAfter()before()insertBefore()wrap()wrapAll()wrapInner()replaceWith()replaceAll()empty()remove()clone()
55.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitieshtml()text()append()appendTo()prepend()prependTo()after()insertAfter()before()insertBefore()wrap()wrapAll()wrapInner()replaceWith()replaceAll()empty()remove()clone()
56.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities<!DOCTYPE html><html><body><p>Make me bold!</p><script src="jquery.js"></script><script>jQuery("p").wrapInner("<b></b>");</script></body></html>http://jsbin.com/esuwu/edit#html
57.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiescss()offset()offsetParent()postion()scrollTop()scrollLeft()height()width()innerHeight()innerWidth()outerHeight()outerWidth()
58.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiescss()offset()offsetParent()postion()scrollTop()scrollLeft()height()width()innerHeight()innerWidth()outerHeight()outerWidth()
59.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities<!DOCTYPE html><html><head><style>div{background-color:#ccc; width:100px; margin:0 20px; float:left;}</style></head><body><div></div><div></div><div></div><script src=“jquery.js" ></script><script>jQuery("div").height(jQuery(document).height());</script></body></html>http://jsbin.com/iseti/edit#html
60.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesblur()change()click()dbclick()error()focus()keydown()keypress()keyup()mousedown()mousenter()mouseleave()mouseout()mouseup()resize()scroll()select()submit()unload()ready()bind()one()trigger()triggerHandler()unbind()live()die()hover()toggle()
61.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesblur()change()click()dbclick()error()focus()keydown()keypress()keyup()mousedown()mousenter()mouseleave()mouseout()mouseup()resize()scroll()select()submit()unload()ready()bind()one()trigger()triggerHandler()unbind()live()die()hover()toggle()
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesshow()hide()toggle()slideDown()slideUp()slideToggle()fadeIn()fadeOut()fadeTo()animate()stop()
65.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesshow()hide()toggle()slideDown()slideUp()slideToggle()fadeIn()fadeOut()fadeTo()animate()stop()
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesshow()hide()toggle()slideDown()slideUp()slideToggle()fadeIn()fadeOut()fadeTo()animate()stop()
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery.ajaxSetup() serialize()serializeArray()jQuery.ajax()jQuery.get()jQuery.getJSON() jQuery,getScript() jQuery.post()load()ajaxComplete()ajaxError()ajaxSend()ajaxStart()ajaxStop()ajaxSuccess()
70.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilitiesjQuery.ajaxSetup() serialize()serializeArray()jQuery.ajax()jQuery.get()jQuery.getJSON()jQuery,getScript() jQuery.post()load()ajaxComplete()ajaxError()ajaxSend()ajaxStart()ajaxStop()ajaxSuccess()
71.
Overview of jQueryAPICoreSelectorsAttributesTraversingManipulationCSSEventsEffectsAjaxUtilities<!DOCTYPE html><html><body><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script><script>jQuery.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=jquery&tagmode=all&format=json&jsoncallback=?",function(data){ jQuery.each(data.items, function(i,item){ jQuery("<img/>") .attr("src", item.media.m) .appendTo("body"); if ( i == 30 ) return false; }); });</script></body></html>http://jsbin.com/ivifa/edit#htmlhttp://jsbin.com/erase/edit#html
A jQueryplugin in6 stepsStep 1. create a private scope for $ alias<!DOCTYPE html><html><body><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){})(jQuery);</script></body></html>
83.
A jQueryplugin in6 stepsStep 2. attach plugin to fn alias (aka prototype)<!DOCTYPE html><html><body><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ $(this).text($(this).text().replace(/hate/g,"love")); }; })(jQuery);</script></body></html>
84.
A jQueryplugin in6 stepsStep 2. attach plugin to fn alias (aka prototype)<!DOCTYPE html><html><body><p>I hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ $(this).text($(this).text().replace(/hate/g,"love")); }; })(jQuery);jQuery("p").loveNotHate();</script></body></html>
85.
A jQueryplugin in6 stepsStep 3. add implicit iteration<!DOCTYPE html><html><body><p>I hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ this.each(function(){$(this).text($(this).text().replace(/hate/g,"love")); }); }; })(jQuery);jQuery("p").loveNotHate();</script></body></html>
86.
A jQueryplugin in6 stepsStep 3. add implicit iteration<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ this.each(function(){ $(this).text($(this).text().replace(/hate/g,"love")); }); }; })(jQuery);jQuery("p").loveNotHate();</script></body></html>
87.
A jQueryplugin in6 stepsStep 4. enable chaining<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ return this.each(function(){ $(this).text($(this).text().replace(/hate/g,"love")); }); }; })(jQuery);jQuery("p").loveNotHate();</script></body></html>
88.
A jQueryplugin in6 stepsStep 4. enable chaining<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ return this.each(function(){ $(this).text($(this).text().replace(/hate/g,"love")); }); }; })(jQuery);jQuery("p").loveNotHate().hide();</script></body></html>
89.
A jQueryplugin in6 stepsStep 5. add default options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ return this.each(function(){ $(this).text($(this).text().replace(/hate/g,$.fn.loveNotHate.defaults.text)); }); }; $.fn.loveNotHate.defaults = {text:"love"};})(jQuery);jQuery("p").loveNotHate();</script></body></html>
90.
A jQueryplugin in6 stepsStep 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate = function(){ return this.each(function(){ $(this).text($(this).text().replace(/hate/g,$.fn.loveNotHate.defaults.text)); }); }; $.fn.loveNotHate.defaults = {text:"love"};})(jQuery);jQuery("p").loveNotHate({text:"love-love-love"});</script></body></html>
91.
A jQueryplugin in6 stepsStep 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate= function(options){ return this.each(function(){ $(this).text($(this).text().replace(/hate/g,$.fn.loveNotHate.defaults.text)); }); }; $.fn.loveNotHate.defaults = {text:"love"};})(jQuery);jQuery("p").loveNotHate({text:"love-love-love"});</script></body></html>
92.
A jQueryplugin in6 stepsStep 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate= function(options){ options = $.extend({},$.fn.loveNotHate.defaults, options);return this.each(function(){ $(this).text($(this).text().replace(/hate/g,$.fn.loveNotHate.defaults.text)); }); }; $.fn.loveNotHate.defaults = {text:"love"};})(jQuery);jQuery("p").loveNotHate({text:"love-love-love"});</script></body></html>
93.
A jQueryplugin in6 stepsStep 6. add custom options<!DOCTYPE html><html><body><p>I hate jQuery!</p><p>I mean really hate jQuery!</p><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script>(function($){ $.fn.loveNotHate= function(options){ options = $.extend({},$.fn.loveNotHate.defaults, options);return this.each(function(){ $(this).text($(this).text().replace(/hate/g,options.text)); }); }; $.fn.loveNotHate.defaults = {text:"love"};})(jQuery);jQuery("p").loveNotHate({text:"love-love-love"});</script></body></html>
jQuery NewsMoving towardsa Conservancy (Software Freedom Law Center) owning the codeTax-deductible donationsFour conferences next year (Boston, San Francisco, London, and online)jQuery.org project siteT-shirtsjQueryForum moving away from Google GroupsRevamp of the plugin site
#5 before we start, for those not already using jQuery, lets answer this question: why bother?if you aren"t using it yet, is anyone else?
#6 Very significant when you consider how many javascript solutions there are out there
#9 It simplifies…dealing – selecting and manipulating elementsevent handling, eg. do something on a click eventanimating – slides, fadesajax – server stuff in the background
#11 Will add a class to each odd table row inside of each table in an html pagenot too complex, already nine lines of codelead in: using jQuery…
#12 Exchange 9 lines of code for a single jQuery statementLets examine this in detail