SlideShare a Scribd company logo
jQuery: Nuts, Bolts and Bling
Doug Neiner
  doug@dougneiner.com

           dougneiner

             dcneiner

          Doug Neiner
My Family
Crystal
Ruby, Olivia, Cody

Not pictured:
Ditto the cat
Iamateam
                                     memberhere
Iamasenior
designerhere
Audience
This presentation was crafted specifically for delivery at the Front End Design
Conference in St. Petersburg, FL. The audience consisted of designers who have
never used jQuery through developers who use jQuery regularly.

The slide portion of this presentation has a lot of getting started information, as
well as some tricks you may or may not know. The live coding portion (available on
Github) contains some more advanced techniques.

If you have any questions after watching this presentation and looking at the code,
please let me know: doug@dougneiner.com (Be sure to reference this presentation
when emailing!)

                                                    D
                                                 AN
jQuery: Nuts, Bolts and Bling
Write working code
Ugly, working code always trumps pretty, broken code




                                  D
                               AN
basics

       D
    AN
Writing the name

     A. Jquery                                                                             C. jquery

     B. JQuery                                                                              D. jQuery
       *It’soktowriteitinallcapswhenthe
           restofthecontextisallcapsaswell.
                                                                                            D
                                                                                         AN
adding scripts
div	
  id=dan	
  I	
  am	
  Dan	
  /div                                              HTML
style
#dan	
  {	
  display:	
  none;	
  }
                                                           Youobviously
/style                                                  wouldn’tdothis
div	
  id=cherrie	
  I	
  am	
  Cherrie	
  /div
style
#cherrie	
  {	
  background:	
  red;	
  }
/style

                                                      D
                                                   AN
adding scripts
div	
  id=dan	
  I	
  am	
  Dan	
  /div                                             HTML
script
$(	
  #dan	
  ).hide();
/script
                                                          Sopleasedon’t
                                                                     dothis
div	
  id=cherrie	
  I	
  am	
  Cherrie	
  /div
script
$(	
  #cherrie	
  ).hide().fadeIn(	
  500	
  );
/script

                                                      D
                                                   AN
adding scripts
	
  	
  div	
  id=dan	
  I	
  am	
  Dan	
  /div
	
  	
  div	
  id=cherrie	
  I	
  am	
  Cherrie	
  /div
                                                                                                           HTML
	
  	
  script	
  src=//ajax.googleapis.com/ajax/                       Better,butnow
libs/jquery/1.6.2/jquery.min.js/script                              #danand#cherrie
	
  	
  script	
  src=js/site.js/script                          blinkonforasplit-
/body                                                                secondbeforehiding

$(	
  #dan	
  ).hide();
$(	
  #cherrie	
  ).hide().fadeIn(	
  500	
  );
                                                                                                                    JS
                                                                   D
                                                                AN
adding scripts
html	
  class=no-­‐js
head                                            NowthetwoelementsarehiddenbyCSS,                     HTML
	
  	
  	
  ...                                    butonlywhenweknowJSisworking
	
  	
  	
  script
	
  	
  	
  	
  	
  	
  document.documentElement.className	
  =	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  document.documentElement.className.replace(	
  no-­‐js,	
  js	
  );
	
  	
  	
  /script
	
  	
  	
  link	
  rel=stylesheet	
  href=css/layout.css	
  /                        IfyouareusingModernizr,it
                                                                                                                           alreadydoesthis,andyou
                                                                                                                              don'tneedthiscode


.js	
  #dan,	
  .js	
  #cherrie	
  {	
  display:	
  none;	
  }                                                                                                                 CSS
                                                                                                   D
                                                                                                AN
adding scripts
	
  	
  div	
  id=dan	
  I	
  am	
  Dan	
  /div
	
  	
  div	
  id=cherrie	
  I	
  am	
  Cherrie	
  /div
                                                                                                           HTML
	
  	
  script	
  src=//ajax.googleapis.com/ajax/                      Nowwecanremove
libs/jquery/1.6.2/jquery.min.js/script                                     thetwo.hide()
	
  	
  script	
  src=js/site.js/script                           statementsandjust
/body                                                                runfadeInon#cherrie

$(	
  #cherrie	
  ).fadeIn(	
  500	
  );                                                                         JS
                                                                   D
                                                                AN
Adding scripts
•   Use at least one external script file for your site, not tons of in-page script
    blocks spread throughout your app.

•   Include references to jQuery and your script just before the closing body tag

    •   Primarily on web sites (on JS-required apps inside head may be ok)

    •   Use no-js and js classes to provide styling until the script loads




                                                      D
                                                   AN
File layout
jQuery(	
  document	
  ).ready(	
  function	
  ()	
  {                                                     JS
	
  	
  jQuery(	
  div	
  ).each(	
  function	
  ()	
  {
	
  	
  	
  	
  jQuery(	
  this	
  ).hide();
	
  	
  });
                                                                             Too…⋯Much…⋯
                                                                               jQuery…⋯
	
  	
  jQuery.getJSON(	
  ...,	
  function	
  (	
  data	
  )	
  {
	
  	
  	
  	
  jQuery.each(	
  data,	
  function	
  ()	
  {	
  ...	
  });
	
  	
  });
});



                                                                D
                                                             AN
File layout
(function	
  (	
  $	
  )	
  {                                           JS
var	
  sample	
  =	
  {	
  sample:	
  true	
  };
//	
  DOM	
  may	
  not	
  be	
  complete

$(	
  document	
  ).ready(	
  function	
  ()	
  {
	
  	
  //	
  DOM	
  is	
  ready.	
  Come	
  and	
  get	
  it!
});

}(	
  jQuery	
  ));

                                                                    D
                                                                 AN
File layout
(function	
  (	
  $	
  )	
  {                                                                                         JS
var	
  sample	
  =	
  {	
  sample:	
  true	
  };
//	
  DOM	
  may	
  not	
  be	
  complete                                 Thisiscalledan
                                                                            Immediately
                                                                         InvokingFunction
$(	
  document	
  ).ready(	
  function	
  ()	
  {                       ExpressionorIIFE.
	
  	
  //	
  DOM	
  is	
  ready.	
  Come	
  and	
  get	
  it!
});

}(	
  jQuery	
  ));

                                                                    D
                                                                 AN
File layout (Alt)
jQuery(	
  document	
  ).ready(	
  function	
  (	
  $	
  )	
  {                                                                    JS
	
  	
  //	
  DOM	
  is	
  ready.	
  Come	
  and	
  get	
  it!
});
                                             Youcansupplyaparameterforthe
                                             anonymousfunctioncallback,andit
                                                          willreferencejQuery.
                                            Usethisasashortcutwhenallyour
                                             codemustrunondocument.ready.

                                                                  D
                                                               AN
CONCEPTS

        D
     AN
Iteration
//	
  Explicit,	
  you	
  realize	
  this	
  is	
  looping	
  over	
  items        JS
$(	
  div	
  ).each(function	
  ()	
  {	
  ...	
  });

//	
  Implicit,	
  you	
  may	
  not	
  realize	
  each	
  call	
  is	
  looping
$(	
  div	
  )
	
  	
  .attr(	
  data-­‐group,	
  doug	
  )
	
  	
  .addClass(	
  dougsGroup	
  )
	
  	
  .hide();



                                                          D
                                                       AN
CSS vs. Class
$(	
  div	
  ).css({                                                                                             JS
	
  	
  	
  width:	
  20,                               Use.css()whenthe
	
  	
  	
  height:	
  500                            valuesmustbedynamic
});
                                                   Useclasseswhenyouknow
//	
  Or:                                           thevaluesaheadoftime.
$(	
  div	
  ).addClass(	
  tall	
  );


.tall	
  {	
  width:	
  20px;	
  height:	
  500px;	
  }                                                            CSS
                                                           D
                                                        AN
Toggle Methods
var	
  div	
  =	
  $(	
  div	
  );                      JS
if	
  (	
  div.hasClass(	
  frontendrocks	
  )	
  {
	
  	
  div.addClass(	
  frontendrocks	
  );
}	
  else	
  {
	
  	
  div.removeClass(	
  frontendrocks	
  );
}

//	
  A	
  better	
  way	
  to	
  write	
  it
div.toggleClass(	
  frontendrocks	
  );

                                                      D
                                                   AN
Toggle Methods
//	
  If	
  you	
  need	
  it	
  to	
  match	
  up	
  to	
  a	
  variable               JS
var	
  something	
  =	
  true,	
  div	
  =	
  $(	
  div	
  );

//	
  This	
  forces	
  the	
  class	
  on	
  or	
  off	
  based	
  on	
  `something`
div.toggleClass(	
  frontendrocks,	
  something	
  );

//	
  Other	
  methods	
  support	
  this	
  too,	
  check	
  the	
  API
div.slideToggle(	
  200,	
  something	
  );
div.toggle(	
  something	
  );

                                                                 D
                                                              AN
updating values
var	
  div	
  =	
  $(	
  div	
  );
//	
  Setting	
  a	
  single	
  key/value
div.attr(	
  key,	
  value	
  );

//	
  Setting	
  more	
  than	
  one	
  key/value	
  at	
  once
div.attr(	
  {	
  key:	
  	
  value,	
  key2:	
  value2	
  });

//	
  Setting	
  the	
  value	
  using	
  a	
  callback	
  function
div.attr(	
  key	
  ,	
  function	
  (i,	
  oldValue	
  )	
  {
	
  	
  return	
  newvalue;
});

                                                                    D
                                                                 AN
updating values
//	
  Other	
  methods	
  support	
  it	
  too,	
  check	
  the	
  API
div.addClass(	
  function	
  (i,	
  val)	
  {

	
  	
  //	
  This	
  returns	
  an	
  incremental	
  class	
  to	
  add	
  for	
  each
	
  	
  //	
  item	
  in	
  the	
  result	
  set
	
  	
  return	
  awesome-­‐	
  +	
  i;
});




                                                                  D
                                                               AN
Asynchronous code
var	
  loaded	
  =	
  false;

$.get(	
  http://url.com,	
  function	
  (	
  data	
  )	
  {
	
  	
  	
  loaded	
  =	
  true;
});                                                 Thismethodwillrunat
                                                                          somepointinthefuture
if	
  (	
  loaded	
  ===	
  true	
  )	
  {
                                                              Thisrunsrightaway,and
	
  	
  //	
  Never	
  runs                                    willexecutebeforethe
}                                                              callbackfor$.getfires.
                                                                      D
                                                                   AN
Asynchronous code
var	
  loaded	
  =	
  false;

$.get(	
  http://url.com,	
  function	
  (	
  data	
  )	
  {
	
  	
  	
  loaded	
  =	
  data.loaded;
	
  	
  	
  if	
  (	
  loaded	
  ===	
  true	
  )	
  {
	
  	
  	
  	
  	
  //	
  This	
  runs	
  when	
  loaded	
  is	
  true
	
  	
  	
  }                                                           Putlogicthatdependson
});                                                                    asynchronouscodeeitherin
                                                                             thecallbackorinafunction
                                                                            youexecutefromthecallback
                                                                                D
                                                                             AN
Lets Code!
          Code is available here:
https://github.com/dcneiner/jquery-bling



                             D
                          AN
Links
•   jQuery Tmpl
    https://github.com/jquery/jquery-tmpl

•   jQuery MockJax
    http://code.appendto.com/plugins/jquery-mockjax

•   jQuery doTimeout
    http://benalman.com/projects/jquery-dotimeout-plugin/

•   Alternate jQuery API
    http://jqapi.com/

                                                  D
                                               AN
Doug Neiner
  doug@dougneiner.com

           dougneiner

             dcneiner

          Doug Neiner

More Related Content

KEY
jQuery('#knowledge').appendTo('#you');
PPTX
FuncUnit
PDF
jQuery in the [Aol.] Enterprise
PDF
Write Less Do More
PDF
Organizing Code with JavascriptMVC
PPTX
Getting the Most Out of jQuery Widgets
PPTX
Unobtrusive javascript with jQuery
PPT
jQuery 1.7 Events
jQuery('#knowledge').appendTo('#you');
FuncUnit
jQuery in the [Aol.] Enterprise
Write Less Do More
Organizing Code with JavascriptMVC
Getting the Most Out of jQuery Widgets
Unobtrusive javascript with jQuery
jQuery 1.7 Events

What's hot (20)

PDF
jQuery Features to Avoid
PDF
jQuery Essentials
PDF
jQuery Loves Developers - Oredev 2009
PDF
OOCSS for JavaScript Pirates jQcon Boston
PDF
jQuery for beginners
PDF
jQuery Introduction
PPTX
PDF
Stack Overflow Austin - jQuery for Developers
PPT
Jquery ui
PPTX
SharePoint and jQuery Essentials
PDF
JavaScript Libraries (Kings of Code)
PPTX
jQuery
PPTX
jQuery Presentation
PDF
Introduction to jQuery
PPTX
A Rich Web Experience with jQuery, Ajax and .NET
KEY
The jQuery Library
PDF
jQuery Essentials
PPTX
A Rich Web experience with jQuery, Ajax and .NET
PPTX
jQuery
jQuery Features to Avoid
jQuery Essentials
jQuery Loves Developers - Oredev 2009
OOCSS for JavaScript Pirates jQcon Boston
jQuery for beginners
jQuery Introduction
Stack Overflow Austin - jQuery for Developers
Jquery ui
SharePoint and jQuery Essentials
JavaScript Libraries (Kings of Code)
jQuery
jQuery Presentation
Introduction to jQuery
A Rich Web Experience with jQuery, Ajax and .NET
The jQuery Library
jQuery Essentials
A Rich Web experience with jQuery, Ajax and .NET
jQuery
Ad

Viewers also liked (19)

PPT
Linked In Features Technical
PDF
How to make Ajax Libraries work for you
PDF
What the heck is HTML 5?
PDF
Web App Security Horror Stories
PDF
Rediscovering JavaScript: The Language Behind The Libraries
PDF
JavaScript Libraries: The Big Picture
PPTX
jQuery for web development
PDF
When Ajax Attacks! Web application security fundamentals
PPT
DOM ( Document Object Model )
PDF
How Lanyrd does Geo
PDF
Javascript and DOM
PPT
Document Object Model
PDF
Introduction to Browser Internals
PDF
Introduction to Browser DOM
PDF
Simplify AJAX using jQuery
PDF
Introduction to EDI(Electronic Data Interchange)
PDF
jQuery and Ajax
PDF
Learning jQuery in 30 minutes
PDF
Unobtrusive JavaScript with jQuery
Linked In Features Technical
How to make Ajax Libraries work for you
What the heck is HTML 5?
Web App Security Horror Stories
Rediscovering JavaScript: The Language Behind The Libraries
JavaScript Libraries: The Big Picture
jQuery for web development
When Ajax Attacks! Web application security fundamentals
DOM ( Document Object Model )
How Lanyrd does Geo
Javascript and DOM
Document Object Model
Introduction to Browser Internals
Introduction to Browser DOM
Simplify AJAX using jQuery
Introduction to EDI(Electronic Data Interchange)
jQuery and Ajax
Learning jQuery in 30 minutes
Unobtrusive JavaScript with jQuery
Ad

Similar to jQuery: Nuts, Bolts and Bling (20)

KEY
Bcblackpool jquery tips
PDF
PDF
PDF
Web2.0 with jQuery in English
PDF
An Introduction to Jquery
PPTX
PPT
Jquery presentation
PDF
Jquery presentation
PDF
handout-05b
PDF
handout-05b
PDF
jQuery (DrupalCamp Toronto)
PPT
J query b_dotnet_ug_meet_12_may_2012
PDF
jQuery (BostonPHP)
PPT
J query presentation
PPT
J query presentation
PPTX
Jquery Complete Presentation along with Javascript Basics
PPTX
Web technologies-course 11.pptx
PPTX
presentation_jquery_ppt.pptx
PPTX
UNIT 1 (7).pptx
KEY
Week 4 - jQuery + Ajax
Bcblackpool jquery tips
Web2.0 with jQuery in English
An Introduction to Jquery
Jquery presentation
Jquery presentation
handout-05b
handout-05b
jQuery (DrupalCamp Toronto)
J query b_dotnet_ug_meet_12_may_2012
jQuery (BostonPHP)
J query presentation
J query presentation
Jquery Complete Presentation along with Javascript Basics
Web technologies-course 11.pptx
presentation_jquery_ppt.pptx
UNIT 1 (7).pptx
Week 4 - jQuery + Ajax

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

jQuery: Nuts, Bolts and Bling

  • 2. Doug Neiner doug@dougneiner.com dougneiner dcneiner Doug Neiner
  • 3. My Family Crystal Ruby, Olivia, Cody Not pictured: Ditto the cat
  • 4. Iamateam memberhere Iamasenior designerhere
  • 5. Audience This presentation was crafted specifically for delivery at the Front End Design Conference in St. Petersburg, FL. The audience consisted of designers who have never used jQuery through developers who use jQuery regularly. The slide portion of this presentation has a lot of getting started information, as well as some tricks you may or may not know. The live coding portion (available on Github) contains some more advanced techniques. If you have any questions after watching this presentation and looking at the code, please let me know: doug@dougneiner.com (Be sure to reference this presentation when emailing!) D AN
  • 7. Write working code Ugly, working code always trumps pretty, broken code D AN
  • 8. basics D AN
  • 9. Writing the name A. Jquery C. jquery B. JQuery D. jQuery *It’soktowriteitinallcapswhenthe restofthecontextisallcapsaswell. D AN
  • 10. adding scripts div  id=dan  I  am  Dan  /div HTML style #dan  {  display:  none;  } Youobviously /style wouldn’tdothis div  id=cherrie  I  am  Cherrie  /div style #cherrie  {  background:  red;  } /style D AN
  • 11. adding scripts div  id=dan  I  am  Dan  /div HTML script $(  #dan  ).hide(); /script Sopleasedon’t dothis div  id=cherrie  I  am  Cherrie  /div script $(  #cherrie  ).hide().fadeIn(  500  ); /script D AN
  • 12. adding scripts    div  id=dan  I  am  Dan  /div    div  id=cherrie  I  am  Cherrie  /div HTML    script  src=//ajax.googleapis.com/ajax/ Better,butnow libs/jquery/1.6.2/jquery.min.js/script #danand#cherrie    script  src=js/site.js/script blinkonforasplit- /body secondbeforehiding $(  #dan  ).hide(); $(  #cherrie  ).hide().fadeIn(  500  ); JS D AN
  • 13. adding scripts html  class=no-­‐js head NowthetwoelementsarehiddenbyCSS, HTML      ... butonlywhenweknowJSisworking      script            document.documentElement.className  =                    document.documentElement.className.replace(  no-­‐js,  js  );      /script      link  rel=stylesheet  href=css/layout.css  / IfyouareusingModernizr,it alreadydoesthis,andyou don'tneedthiscode .js  #dan,  .js  #cherrie  {  display:  none;  } CSS D AN
  • 14. adding scripts    div  id=dan  I  am  Dan  /div    div  id=cherrie  I  am  Cherrie  /div HTML    script  src=//ajax.googleapis.com/ajax/ Nowwecanremove libs/jquery/1.6.2/jquery.min.js/script thetwo.hide()    script  src=js/site.js/script statementsandjust /body runfadeInon#cherrie $(  #cherrie  ).fadeIn(  500  ); JS D AN
  • 15. Adding scripts • Use at least one external script file for your site, not tons of in-page script blocks spread throughout your app. • Include references to jQuery and your script just before the closing body tag • Primarily on web sites (on JS-required apps inside head may be ok) • Use no-js and js classes to provide styling until the script loads D AN
  • 16. File layout jQuery(  document  ).ready(  function  ()  { JS    jQuery(  div  ).each(  function  ()  {        jQuery(  this  ).hide();    }); Too…⋯Much…⋯ jQuery…⋯    jQuery.getJSON(  ...,  function  (  data  )  {        jQuery.each(  data,  function  ()  {  ...  });    }); }); D AN
  • 17. File layout (function  (  $  )  { JS var  sample  =  {  sample:  true  }; //  DOM  may  not  be  complete $(  document  ).ready(  function  ()  {    //  DOM  is  ready.  Come  and  get  it! }); }(  jQuery  )); D AN
  • 18. File layout (function  (  $  )  { JS var  sample  =  {  sample:  true  }; //  DOM  may  not  be  complete Thisiscalledan Immediately InvokingFunction $(  document  ).ready(  function  ()  { ExpressionorIIFE.    //  DOM  is  ready.  Come  and  get  it! }); }(  jQuery  )); D AN
  • 19. File layout (Alt) jQuery(  document  ).ready(  function  (  $  )  { JS    //  DOM  is  ready.  Come  and  get  it! }); Youcansupplyaparameterforthe anonymousfunctioncallback,andit willreferencejQuery. Usethisasashortcutwhenallyour codemustrunondocument.ready. D AN
  • 20. CONCEPTS D AN
  • 21. Iteration //  Explicit,  you  realize  this  is  looping  over  items JS $(  div  ).each(function  ()  {  ...  }); //  Implicit,  you  may  not  realize  each  call  is  looping $(  div  )    .attr(  data-­‐group,  doug  )    .addClass(  dougsGroup  )    .hide(); D AN
  • 22. CSS vs. Class $(  div  ).css({ JS      width:  20, Use.css()whenthe      height:  500 valuesmustbedynamic }); Useclasseswhenyouknow //  Or: thevaluesaheadoftime. $(  div  ).addClass(  tall  ); .tall  {  width:  20px;  height:  500px;  } CSS D AN
  • 23. Toggle Methods var  div  =  $(  div  ); JS if  (  div.hasClass(  frontendrocks  )  {    div.addClass(  frontendrocks  ); }  else  {    div.removeClass(  frontendrocks  ); } //  A  better  way  to  write  it div.toggleClass(  frontendrocks  ); D AN
  • 24. Toggle Methods //  If  you  need  it  to  match  up  to  a  variable JS var  something  =  true,  div  =  $(  div  ); //  This  forces  the  class  on  or  off  based  on  `something` div.toggleClass(  frontendrocks,  something  ); //  Other  methods  support  this  too,  check  the  API div.slideToggle(  200,  something  ); div.toggle(  something  ); D AN
  • 25. updating values var  div  =  $(  div  ); //  Setting  a  single  key/value div.attr(  key,  value  ); //  Setting  more  than  one  key/value  at  once div.attr(  {  key:    value,  key2:  value2  }); //  Setting  the  value  using  a  callback  function div.attr(  key  ,  function  (i,  oldValue  )  {    return  newvalue; }); D AN
  • 26. updating values //  Other  methods  support  it  too,  check  the  API div.addClass(  function  (i,  val)  {    //  This  returns  an  incremental  class  to  add  for  each    //  item  in  the  result  set    return  awesome-­‐  +  i; }); D AN
  • 27. Asynchronous code var  loaded  =  false; $.get(  http://url.com,  function  (  data  )  {      loaded  =  true; }); Thismethodwillrunat somepointinthefuture if  (  loaded  ===  true  )  { Thisrunsrightaway,and    //  Never  runs willexecutebeforethe } callbackfor$.getfires. D AN
  • 28. Asynchronous code var  loaded  =  false; $.get(  http://url.com,  function  (  data  )  {      loaded  =  data.loaded;      if  (  loaded  ===  true  )  {          //  This  runs  when  loaded  is  true      } Putlogicthatdependson }); asynchronouscodeeitherin thecallbackorinafunction youexecutefromthecallback D AN
  • 29. Lets Code! Code is available here: https://github.com/dcneiner/jquery-bling D AN
  • 30. Links • jQuery Tmpl https://github.com/jquery/jquery-tmpl • jQuery MockJax http://code.appendto.com/plugins/jquery-mockjax • jQuery doTimeout http://benalman.com/projects/jquery-dotimeout-plugin/ • Alternate jQuery API http://jqapi.com/ D AN
  • 31. Doug Neiner doug@dougneiner.com dougneiner dcneiner Doug Neiner