jQuery: Nuts, Bolts and Bling
Upcoming SlideShare
Loading in...5

Like this? Share it with your network


jQuery: Nuts, Bolts and Bling

Uploaded on

This presentation covers some jQuery basics, as well as some general concepts you should understand about jQuery. You will find other tips and tricks sprinkled throughout before the live coding......

This presentation covers some jQuery basics, as well as some general concepts you should understand about jQuery. You will find other tips and tricks sprinkled throughout before the live coding session starts.

The code from the live coding session is available here: https://github.com/dcneiner/jQuery-Bling and covers far more advanced topics than the slide portion of this presentation.

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads


Total Views
On Slideshare
From Embeds
Number of Embeds



Embeds 837

http://wrccdesign.com.br 781
http://saifulmuhajir.me 30
http://saifulmuhajir.web.id 15
http://zootool.com 4
http://localhost 4
http://www.linkedin.com 2
https://si0.twimg.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Doug Neiner doug@dougneiner.com dougneiner dcneiner Doug Neiner
  • 2. My FamilyCrystalRuby, Olivia, CodyNot pictured:Ditto the cat
  • 3. Iamateam memberhereIamaseniordesignerhere
  • 4. AudienceThis presentation was crafted specifically for delivery at the Front End DesignConference in St. Petersburg, FL. The audience consisted of designers who havenever used jQuery through developers who use jQuery regularly.The slide portion of this presentation has a lot of getting started information, aswell as some tricks you may or may not know. The live coding portion (available onGithub) 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 presentationwhen emailing!) D AN
  • 5. Write working codeUgly, working code always trumps pretty, broken code D AN
  • 6. basics D AN
  • 7. Writing the name A. Jquery C. jquery B. JQuery D. jQuery *It’soktowriteitinallcapswhenthe restofthecontextisallcapsaswell. D AN
  • 8. 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
  • 9. 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
  • 10. adding scripts    <div  id="dan">  I  am  Dan  </div>    <div  id="cherrie">  I  am  Cherrie  </div> HTML    <script  src="//ajax.googleapis.com/ajax/ Better,butnowlibs/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
  • 11. 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 dontneedthiscode.js  #dan,  .js  #cherrie  {  display:  none;  } CSS 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/ Nowwecanremovelibs/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
  • 13. 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
  • 14. File layoutjQuery(  document  ).ready(  function  ()  { JS    jQuery(  "div"  ).each(  function  ()  {        jQuery(  this  ).hide();    }); Too…⋯Much…⋯ jQuery…⋯    jQuery.getJSON(  "...",  function  (  data  )  {        jQuery.each(  data,  function  ()  {  ...  });    });}); D AN
  • 15. File layout(function  (  $  )  { JSvar  sample  =  {  sample:  true  };//  DOM  may  not  be  complete$(  document  ).ready(  function  ()  {    //  DOM  is  ready.  Come  and  get  it!});}(  jQuery  )); D AN
  • 16. File layout(function  (  $  )  { JSvar  sample  =  {  sample:  true  };//  DOM  may  not  be  complete Thisiscalledan "Immediately InvokingFunction$(  document  ).ready(  function  ()  { Expression"orIIFE.    //  DOM  is  ready.  Come  and  get  it!});}(  jQuery  )); D AN
  • 17. File layout (Alt)jQuery(  document  ).ready(  function  (  $  )  { JS    //  DOM  is  ready.  Come  and  get  it!}); Youcansupplyaparameterforthe anonymousfunctioncallback,andit willreferencejQuery. Usethisasashortcutwhenallyour codemustrunondocument.ready. D AN
  • 19. 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
  • 20. 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
  • 21. Toggle Methodsvar  div  =  $(  "div"  ); JSif  (  div.hasClass(  "frontendrocks"  )  {    div.addClass(  "frontendrocks"  );}  else  {    div.removeClass(  "frontendrocks"  );}//  A  better  way  to  write  itdiv.toggleClass(  "frontendrocks"  ); D AN
  • 22. Toggle Methods//  If  you  need  it  to  match  up  to  a  variable JSvar  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  APIdiv.slideToggle(  200,  something  );div.toggle(  something  ); D AN
  • 23. updating valuesvar  div  =  $(  "div"  );//  Setting  a  single  key/valuediv.attr(  "key",  "value"  );//  Setting  more  than  one  key/value  at  oncediv.attr(  {  "key":    "value",  "key2":  "value2"  });//  Setting  the  value  using  a  callback  functiondiv.attr(  "key"  ,  function  (i,  oldValue  )  {    return  "newvalue";}); D AN
  • 24. updating values//  Other  methods  support  it  too,  check  the  APIdiv.addClass(  function  (i,  val)  {    //  This  returns  an  incremental  class  to  add  for  each    //  item  in  the  result  set    return  "awesome-­‐"  +  i;}); D AN
  • 25. Asynchronous codevar  loaded  =  false;$.get(  "http://url.com",  function  (  data  )  {      loaded  =  true;}); Thismethodwillrunat "somepointinthefuture"if  (  loaded  ===  true  )  { Thisrunsrightaway,and    //  Never  runs willexecutebeforethe} callbackfor$.getfires. D AN
  • 26. Asynchronous codevar  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
  • 27. Lets Code! Code is available here:https://github.com/dcneiner/jquery-bling D AN
  • 28. 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
  • 29. Doug Neiner doug@dougneiner.com dougneiner dcneiner Doug Neiner