Short intro to JQuery and Modernizr

Jussi Pohjolainen
Jussi PohjolainenSenior Lecturer à Tampere University of Applied Sciences
Short	
  into	
  to	
  JQuery	
  and	
  
          Modernizr	
  
            Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
JQuery?	
  
•  Mo?va?on	
  
   –  Simple	
  things	
  may	
  require	
  lot	
  of	
  coding	
  
   –  Common	
  browsers	
  are	
  different	
  and	
  
      implementa?on	
  varies	
  
•  Solu?on,	
  use	
  a	
  framework	
  
   –  jQuery	
  is	
  a	
  fast	
  and	
  concise	
  JavaScript	
  Library	
  that	
  
        simplifies	
  HTML	
  document	
  traversing,	
  event	
  
        handling,	
  anima?ng,	
  and	
  Ajax	
  interac?ons	
  for	
  
        rapid	
  web	
  development.	
  	
  
   	
  
How?	
  
•  Download	
  JQuery	
  file	
  (hOp://jquery.com/)	
  
    –  hOp://code.jquery.com/jquery-­‐1.7.1.min.js	
  
•  Make	
  your	
  xhtml	
  page	
  and	
  reference	
  to	
  the	
  
   file	
  in	
  script	
  block	
  
•  Make	
  your	
  code	
  and	
  use	
  JQuery	
  func?ons!	
  
<script type="text/javascript" src="jquery.js"></script>

   <script type="text/javascript">
   //<![CDATA[

    // When document is ready to be manipulated
    jQuery(document).ready( pageReadyToBeManipulated );

    function pageReadyToBeManipulated() {
        // If link is clicked
        jQuery("a").click( linkClick );
    }

    function linkClick(event) {
        alert("Thanks for visiting!");
        // Prevent the default action
        event.preventDefault();
    }

    //]]>
   </script>
Some	
  Basic	
  Syntax	
  
•  JQuery	
  can	
  be	
  used	
  in	
  two	
  ways:	
  
    –  JQuery()	
  
    –  Or	
  
    –  $()	
  
•  $	
  is	
  an	
  alias	
  to	
  JQuery()!	
  $	
  more	
  commonly	
  
   used	
  
<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">
//<![CDATA[

 // When document is ready to be manipulated
 $(document).ready( pageReadyToBeManipulated );

 function pageReadyToBeManipulated() {
     // If link is clicked
     $("a").click( linkClick );
 }

 function linkClick(event) {
     alert("Thanks for visiting!");
     // Prevent the default action
     event.preventDefault();
 }

 //]]>
</script>
// USING ANONYMOUS FUNCTIONS

<script type="text/javascript" src="jquery.js"></script>

 <script type="text/javascript">
 //<![CDATA[

  $(document).ready(function(){
      $("a").click(function(event){
          alert("Thanks for visiting!");
          event.preventDefault();
      });
  });

  //]]>
 </script>
// EVEN SHORTER SYNTAX, FORGET THE DOCUMENT PARAMETER

<script type="text/javascript" src="jquery.js"></script>

 <script type="text/javascript">
 //<![CDATA[

  $().ready(function(){
      $("a").click(function(event){
          alert("Thanks for visiting!");
          event.preventDefault();
      });
  });

  //]]>
 </script>
GeOers	
  in	
  the	
  Tradi?onal	
  Way	
  
•  getElementsById

•  getElementsByTagName

•  getAttribute
JQuery	
  and	
  Selectors	
  
•  Select	
  all	
  h1	
  elements	
  
    –  $(“h1”)	
  
•  Select	
  the	
  first	
  one	
  
    –  $(“h1”)[0]	
  
•  Add	
  contents	
  
    –  $(“h1”)[0].innerHTML	
  =	
  “hello!”;	
  
•  Lot	
  of	
  different	
  selectors	
  
    –  hOp://api.jquery.com/category/selectors/	
  
Crea?ng	
  Elements	
  in	
  Tradi?onal	
  Way	
  
•    createElement
•    createTextNode
•    setAttribute
•    appendChild
•    removeChild
JQuery	
  Insert	
  
$().ready(function(){
       $("a").click(function(event){

               // Insert the new element after element with id here
               $("<p>New Element</p>").insertAfter("#here");

               event.preventDefault();
         });
   });
Manipula?on	
  Func?ons	
  
•    .addClass()	
  
•    .afer()	
  
•    .append()	
  
•    .css()	
  
•    …	
  
•    See:	
  hOp://api.jquery.com/category/
     manipula?on/	
  
Some	
  Effects:	
  Lot	
  of	
  Anim	
  Func?ons	
  
$('#clickme').click(function() {
  $('#book').slideUp('slow', function() {
    // Animation complete.
  });
});
MODERNIZR	
  
Modernizr	
  
•  Small	
  JS	
  library	
  for	
  detec?ng	
  browser	
  features	
  
•  Replaces	
  highly	
  unreliable	
  user	
  agent	
  sniffing	
  
•  Feature	
  detec?on	
  for	
  each	
  browser	
  what	
  the	
  
   browser	
  can	
  or	
  cannot	
  do	
  
•  Tests	
  over	
  40	
  features	
  
    –  Creates	
  Modernizr	
  object	
  containing	
  the	
  results	
  
How	
  
•  Download	
  and	
  install	
  modernizr.js	
  
•  Add	
  
    –  <html	
  class=“no-­‐js”>	
  
•  Modernizr	
  replaces	
  this	
  
    –  <html	
  class=“canvas	
  canvastext	
  geoloca?on..”>	
  
•  Classes	
  for	
  every	
  feature	
  it	
  detects!	
  
Short intro to JQuery and Modernizr
Adding	
  CSS	
  
Result	
  
HTML5	
  and	
  Video	
  
Solu?on	
  
1 sur 22

Recommandé

State of jQuery and DrupalState of jQuery and Drupal
State of jQuery and Drupaljeresig
1.3K vues21 diapositives
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax pluginsInbal Geffen
366 vues9 diapositives
Railsbridge   javascriptRailsbridge   javascript
Railsbridge javascriptp4geoff
185 vues15 diapositives

Contenu connexe

Tendances

jQuery EssentialsjQuery Essentials
jQuery EssentialsBedis ElAchèche
2.8K vues83 diapositives
Jquery presentationJquery presentation
Jquery presentationMevin Mohan
44 vues18 diapositives
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
2.6K vues39 diapositives
Dart and AngularDartDart and AngularDart
Dart and AngularDartLoc Nguyen
1K vues31 diapositives

Tendances(18)

jQuery EssentialsjQuery Essentials
jQuery Essentials
Bedis ElAchèche2.8K vues
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
Kaloyan Kosev3.5K vues
Jquery presentationJquery presentation
Jquery presentation
Mevin Mohan44 vues
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee2.6K vues
Quick Intro to JQuery and JQuery MobileQuick Intro to JQuery and JQuery Mobile
Quick Intro to JQuery and JQuery Mobile
Jussi Pohjolainen1.1K vues
Dart and AngularDartDart and AngularDart
Dart and AngularDart
Loc Nguyen1K vues
Auto toolsAuto tools
Auto tools
祺 周313 vues
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
Simon Willison41.5K vues
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
chandrashekher786654 vues
Client-side TransformationsClient-side Transformations
Client-side Transformations
John Boxall228 vues
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
tutorialsruby263 vues
Introducing jQueryIntroducing jQuery
Introducing jQuery
Wildan Maulana1.1K vues

Similaire à Short intro to JQuery and Modernizr(20)

JQueryJQuery
JQuery
Jussi Pohjolainen1.2K vues
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
Muhammad Ehtisham Siddiqui244 vues
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Collaboration Technologies149 vues
jQueryjQuery
jQuery
PumoTechnovation31 vues
jQuery for web developmentjQuery for web development
jQuery for web development
iFour Institute - Sustainable Learning316 vues
JQuery UIJQuery UI
JQuery UI
Gary Yeh1.2K vues
JQueryJQuery
JQuery
baabtra.com - No. 1 supplier of quality freshers652 vues
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
Gonzalo Parra684 vues
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
Jennifer Bourey1.6K vues
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
Salvatore Fazio883 vues
J query trainingJ query training
J query training
FIS - Fidelity Information Services429 vues
J query presentationJ query presentation
J query presentation
akanksha17134 vues
J query presentationJ query presentation
J query presentation
sawarkar17932 vues
20111014 mu me_j_querymobile20111014 mu me_j_querymobile
20111014 mu me_j_querymobile
Erik Duval435 vues

Plus de Jussi Pohjolainen

Moved to SpeakerdeckMoved to Speakerdeck
Moved to SpeakerdeckJussi Pohjolainen
1.7K vues1 diapositive
Java Web ServicesJava Web Services
Java Web ServicesJussi Pohjolainen
1.7K vues194 diapositives
Box2D and libGDXBox2D and libGDX
Box2D and libGDXJussi Pohjolainen
3.1K vues28 diapositives
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled MapsJussi Pohjolainen
3.6K vues33 diapositives

Plus de Jussi Pohjolainen(20)

Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
Jussi Pohjolainen1.7K vues
Java Web ServicesJava Web Services
Java Web Services
Jussi Pohjolainen1.7K vues
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
Jussi Pohjolainen3.1K vues
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen2.2K vues
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
Jussi Pohjolainen3.6K vues
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen2.2K vues
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Jussi Pohjolainen1.6K vues
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen9.7K vues
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
Jussi Pohjolainen5.6K vues
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen1.5K vues
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen4.7K vues
libGDX: User InputlibGDX: User Input
libGDX: User Input
Jussi Pohjolainen3K vues
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen2.8K vues
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen2K vues
Android ThreadingAndroid Threading
Android Threading
Jussi Pohjolainen2.2K vues
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen1.1K vues
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
Jussi Pohjolainen873 vues

Dernier(20)

The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya51 vues
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman152 vues
[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh34 vues

Short intro to JQuery and Modernizr

  • 1. Short  into  to  JQuery  and   Modernizr   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. JQuery?   •  Mo?va?on   –  Simple  things  may  require  lot  of  coding   –  Common  browsers  are  different  and   implementa?on  varies   •  Solu?on,  use  a  framework   –  jQuery  is  a  fast  and  concise  JavaScript  Library  that   simplifies  HTML  document  traversing,  event   handling,  anima?ng,  and  Ajax  interac?ons  for   rapid  web  development.      
  • 3. How?   •  Download  JQuery  file  (hOp://jquery.com/)   –  hOp://code.jquery.com/jquery-­‐1.7.1.min.js   •  Make  your  xhtml  page  and  reference  to  the   file  in  script  block   •  Make  your  code  and  use  JQuery  func?ons!  
  • 4. <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> //<![CDATA[ // When document is ready to be manipulated jQuery(document).ready( pageReadyToBeManipulated ); function pageReadyToBeManipulated() { // If link is clicked jQuery("a").click( linkClick ); } function linkClick(event) { alert("Thanks for visiting!"); // Prevent the default action event.preventDefault(); } //]]> </script>
  • 5. Some  Basic  Syntax   •  JQuery  can  be  used  in  two  ways:   –  JQuery()   –  Or   –  $()   •  $  is  an  alias  to  JQuery()!  $  more  commonly   used  
  • 6. <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> //<![CDATA[ // When document is ready to be manipulated $(document).ready( pageReadyToBeManipulated ); function pageReadyToBeManipulated() { // If link is clicked $("a").click( linkClick ); } function linkClick(event) { alert("Thanks for visiting!"); // Prevent the default action event.preventDefault(); } //]]> </script>
  • 7. // USING ANONYMOUS FUNCTIONS <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> //<![CDATA[ $(document).ready(function(){ $("a").click(function(event){ alert("Thanks for visiting!"); event.preventDefault(); }); }); //]]> </script>
  • 8. // EVEN SHORTER SYNTAX, FORGET THE DOCUMENT PARAMETER <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> //<![CDATA[ $().ready(function(){ $("a").click(function(event){ alert("Thanks for visiting!"); event.preventDefault(); }); }); //]]> </script>
  • 9. GeOers  in  the  Tradi?onal  Way   •  getElementsById •  getElementsByTagName •  getAttribute
  • 10. JQuery  and  Selectors   •  Select  all  h1  elements   –  $(“h1”)   •  Select  the  first  one   –  $(“h1”)[0]   •  Add  contents   –  $(“h1”)[0].innerHTML  =  “hello!”;   •  Lot  of  different  selectors   –  hOp://api.jquery.com/category/selectors/  
  • 11. Crea?ng  Elements  in  Tradi?onal  Way   •  createElement •  createTextNode •  setAttribute •  appendChild •  removeChild
  • 12. JQuery  Insert   $().ready(function(){ $("a").click(function(event){ // Insert the new element after element with id here $("<p>New Element</p>").insertAfter("#here"); event.preventDefault(); }); });
  • 13. Manipula?on  Func?ons   •  .addClass()   •  .afer()   •  .append()   •  .css()   •  …   •  See:  hOp://api.jquery.com/category/ manipula?on/  
  • 14. Some  Effects:  Lot  of  Anim  Func?ons   $('#clickme').click(function() { $('#book').slideUp('slow', function() { // Animation complete. }); });
  • 16. Modernizr   •  Small  JS  library  for  detec?ng  browser  features   •  Replaces  highly  unreliable  user  agent  sniffing   •  Feature  detec?on  for  each  browser  what  the   browser  can  or  cannot  do   •  Tests  over  40  features   –  Creates  Modernizr  object  containing  the  results  
  • 17. How   •  Download  and  install  modernizr.js   •  Add   –  <html  class=“no-­‐js”>   •  Modernizr  replaces  this   –  <html  class=“canvas  canvastext  geoloca?on..”>   •  Classes  for  every  feature  it  detects!