SlideShare a Scribd company logo
jQuery Introduction Twitter: @tomijuhola Tomi Juhola, 29.8.2011 Versio:  |  Status:      |  Updated: 0.1 Draft Tomi Juhola, 29.8.2011
Motivation? Target? jQuery is not much educated technology We have a need with people having JavaScript & jQuery skills, as well as an idea how it should be used Target: Familiarize you with the JavaScript and jQuery library Get to know the mostly used parts of jQuery Give guidance on the first steps towards client-side scripting mastery
Agenda JAVASCRIPT BASICS JQUERY BASICS DOM MANIPULATION EVENTS ANIMATIONS JQUERY UI ADDITIONAL RESOURCES
JavaScript Basics 01
What is JavaScript? Scripting language  Dynamic (e.g. objects can be extended during run-time) Weakly-typed (No type needed for variables) Multiparadigm:  Object-oriented Imperative (statements that change program state) Functional (more mathematical model of imperative programming) Prototype based (uses object cloning instead of inheritance) First-class functions (passing functions as parameters to other functions etc.) Implementation of ECMAScript language standard Used mainly on client-side web interfaces
JavaScript syntax JS syntax is C-style, so also close to Java However, JavaScript has really nothing else to do with Java.. Basic statements for ( var i = 0; i < 3; i++ ) {   // DO SOMETHING }  for ( var i in array) {   // DO SOMETHING USEFUL  } while ( true ) {   // DO SOMETHING FOREVER } If (a == b+2)
More simple code examples var variable = ”String”;  Variables scoped to the function, not just the block: function isTen(a){ if (a==10) { var result = ”Success!” } return result; }
Even more simple code examples var myFirstObject = {name: ”Peter”, age: 12}; myFirstObject.name = ”Pete”; if (myFirstObject.age <18) return ”no fun allowed”; Oh, and how to use? <script type=&quot;text/javascript&quot;> document.write('Hello World!'); </script> <noscript> <p>No JS Support!.</p> </noscript>
Issues Cross-browser support DOM (Document Object Model) might be too complicated So HTML page structure No compile time  checking No compile time  at all :) Can be easily disabled Security: XSS (Cross-site scripting), CSRF (Cross-site request forgery) Not easily testable code
jQuery Basics 02
What is jQuery? JavaScript library Cross-browser support Aimed for client-side scripting Released in 2006 Most popular JS library today FOSS (Free and Open Source Software) Licensed under MIT license and GPLv2 Under active development, industry support www.jquery.com You’ll only need the  jquery-1.2.6.min.js  file and one line:  <script type=&quot;text/javascript&quot; src=&quot;jquery-1.2.6.min.js“></script>   to enable all the goodness!
jQuery features DOM elements: select, modify Events CSS handling Flashy effects Ajax Plugin framework Some utility functions (browser version) Very easy to use! And still everything should be cross-browser supported!
DOM manipulation 03
The Focus of jQuery Thanks to John Resig (JavaScript and jQuery, ACM Northeastern University) jQuery object $ (also valid: jQuery(”div”)… )
Examples $(”div”) Selects all divs $(”.myClass”) Selects all items with myClass class $(”#myId”) Selects all items with myId id (should be just one!) $(”div.myClass”) Selects all divs with myClass class $(”div.myClass”).append(”<p>Text text text</p>”); Appends paragrahps to selected divs $(”#myId”).css({font-weight: ”bold”});
Test page <!DOCTYPE html> <head> <title>jQuery test</title> </head> <body>  <script src=&quot;jquery-1.6.2.min.js&quot;></script> <script> $(document).ready(function(){ $(&quot;.changeMe&quot;).append(&quot;<p>Testing append</p>&quot;); }); </script> <div class=&quot;changeMe&quot;>Text1</div> <div class=&quot;dontChangeMe&quot;>Text2<div>  </body> </html> See more at:  http://ejohn.org/files/javascript.pdf
Events 04
Examples $(document).ready(function(){  $(&quot;a&quot;). click (function(event){  alert(“You clicked a link, but I won’t let you away&quot;);  event.preventDefault();  });  });  $(document).ready(function(){ $(&quot;div&quot;). hover (function () { $(this).append($(&quot;<span> Selected!</span>&quot;)); },  function () { $(this).find(&quot;span:last&quot;).remove(); }); });
$.ajax example $.ajax({ url: 'ajax/endpoint',  success: function(data) {   $('#resultDiv').html(data);   alert('DONE!');   } });
Animations 05
Animation examples $(document).ready(function(){ $(&quot;a&quot;).click(function(event){ event.preventDefault(); $(this). hide(&quot;slow&quot;); }); }); $(document).ready(function(){ $('div').click(function() { $('#dilbert'). slideToggle ('slow', function() {}); }); });
jQuery UI 06
jQuery UI http://jqueryui.com/ Built on top of the jQuery library Includes Widgets Effects Animations All including theme support , cross browser support, styling, internationalization etc.
Using e.g. accordion widget <link rel=&quot;stylesheet&quot; href=&quot;themes/base/jquery.ui.all.css&quot;> <script src=&quot;jquery-1.6.2.min.js&quot;></script> <script src=&quot;ui/jquery.ui.core.js&quot;></script> <script src=&quot;ui/jquery.ui.widget.js&quot;></script> <script src=&quot;ui/jquery.ui.accordion.js&quot;></script> ... $(function() { $( &quot;#accordion&quot; ).accordion({ autoHeight: false, navigation: true }); });
Additional resources 07
Web resources http://jquery.com/ http://jqueryui.com/ http://www.w3schools.com/js/default.asp http://www.learningjquery.com/ http://woorkup.com/2011/05/12/jquery-visual-cheat-sheet-1-6/ http://net.tutsplus.com/tutorials/javascript-ajax/simple-draggable-element-persistence-with-jquery/ https://developer.mozilla.org/en/JavaScript
Further reading jQuery in Action by Bear Bibeault and Yehida Kayz (Manning) Learning jQuery 1.3 by Jonathan Chaffer and Karl Swedberg (Packt) jQuery Cookbook by Cody Lindley (O’Reilly) jQuery: Novice to Ninja by Earle Castledine and Craig Sharkie (SitePoint) JavaScript, A Beginner’s Guide by John Pollock (McGraw-Hill) JavaScript: The Definitive Guide by David Flanagan (O’Reilly)
www.lindorff.fi Thank you! Tomi Juhola Development Lead mobile: +358 44 033 8639 [email_address] www.lindorff.fi Joukahaisenkatu 2 FI-20100 Turku

More Related Content

What's hot (20)

PDF
jQuery Features to Avoid
dmethvin
 
PPTX
Unobtrusive javascript with jQuery
Angel Ruiz
 
PPTX
Getting the Most Out of jQuery Widgets
velveeta_512
 
PPTX
Maintainable JavaScript 2012
Nicholas Zakas
 
PPT
JQuery introduction
NexThoughts Technologies
 
PPTX
jQuery
Vishwa Mohan
 
PDF
Introduction to jQuery
Zeeshan Khan
 
PDF
jQuery for beginners
Siva Arunachalam
 
PDF
jQuery Essentials
Bedis ElAchèche
 
PDF
Learn css3
Mostafa Bayomi
 
PPTX
JavaScript and jQuery Basics
Kaloyan Kosev
 
KEY
The jQuery Library
LearnNowOnline
 
PDF
Write Less Do More
Remy Sharp
 
PPT
J Query
ravinxg
 
PDF
D3.js and SVG
Karol Depka Pradzinski
 
PPT
jQuery
Mohammed Arif
 
PPTX
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
PDF
JavaScript Library Overview
jeresig
 
PDF
jQuery Essentials
Marc Grabanski
 
jQuery Features to Avoid
dmethvin
 
Unobtrusive javascript with jQuery
Angel Ruiz
 
Getting the Most Out of jQuery Widgets
velveeta_512
 
Maintainable JavaScript 2012
Nicholas Zakas
 
JQuery introduction
NexThoughts Technologies
 
jQuery
Vishwa Mohan
 
Introduction to jQuery
Zeeshan Khan
 
jQuery for beginners
Siva Arunachalam
 
jQuery Essentials
Bedis ElAchèche
 
Learn css3
Mostafa Bayomi
 
JavaScript and jQuery Basics
Kaloyan Kosev
 
The jQuery Library
LearnNowOnline
 
Write Less Do More
Remy Sharp
 
J Query
ravinxg
 
D3.js and SVG
Karol Depka Pradzinski
 
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
JavaScript Library Overview
jeresig
 
jQuery Essentials
Marc Grabanski
 

Viewers also liked (20)

ODP
Introduction to jQuery
manugoel2003
 
PPTX
Introduction to JSON & AJAX
Collaboration Technologies
 
PPTX
Introduction to JavaScript Programming
Collaboration Technologies
 
PPTX
An Introduction to the DOM
Mindy McAdams
 
PPT
Document Object Model
chomas kandar
 
PPT
Forms authentication
SNJ Chaudhary
 
PPTX
Java swing
profbnk
 
PPT
2310 b 09
Krazy Koder
 
ODP
Nosql availability & integrity
Fahri Firdausillah
 
PPT
Perl Development
Mindfire Solutions
 
PPT
01 Ajax Intro
Dennis Pipper
 
PPT
2310 b 11
Krazy Koder
 
PPTX
Introduction To Silverlight and Prism
tombeuckelaere
 
PDF
PyCologne
Andreas Schreiber
 
PPT
Oid structure
Remco Boksebeld
 
PDF
5 Key Components of Genrocket
GenRocket
 
PPT
Ajax & ASP.NET 2
Talal Alsubaie
 
PPT
Oracle 10g Application Server
Mark J. Feldman
 
PDF
Java/Swing
Momentum Design Lab
 
PPT
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
Introduction to jQuery
manugoel2003
 
Introduction to JSON & AJAX
Collaboration Technologies
 
Introduction to JavaScript Programming
Collaboration Technologies
 
An Introduction to the DOM
Mindy McAdams
 
Document Object Model
chomas kandar
 
Forms authentication
SNJ Chaudhary
 
Java swing
profbnk
 
2310 b 09
Krazy Koder
 
Nosql availability & integrity
Fahri Firdausillah
 
Perl Development
Mindfire Solutions
 
01 Ajax Intro
Dennis Pipper
 
2310 b 11
Krazy Koder
 
Introduction To Silverlight and Prism
tombeuckelaere
 
Oid structure
Remco Boksebeld
 
5 Key Components of Genrocket
GenRocket
 
Ajax & ASP.NET 2
Talal Alsubaie
 
Oracle 10g Application Server
Mark J. Feldman
 
Itp 120 Chapt 19 2009 Binary Input & Output
phanleson
 
Ad

Similar to jQuery introduction (20)

PPTX
Microsoft and jQuery
Eric ShangKuan
 
PPT
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
PDF
High Performance JavaScript 2011
Nicholas Zakas
 
ODP
Developing and testing ajax components
Ignacio Coloma
 
PPTX
J Query Presentation
Vishal Kumar
 
PPT
Jsp
DSKUMAR G
 
PPT
jQuery and_drupal
BlackCatWeb
 
PPT
JWU Guest Talk: JavaScript and AJAX
Hilary Mason
 
PPT
Javascript 2009
borkweb
 
PPT
Introduction to javaScript
Neil Ghosh
 
ODP
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
PPT
Building Smart Workflows - Dan Diebolt
QuickBase, Inc.
 
PPT
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Sergey Ilinsky
 
PPTX
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 
PPT
Jsfsunum
cagataycivici
 
PPT
Even Faster Web Sites at jQuery Conference '09
Steve Souders
 
PPT
JavaScript: Ajax & DOM Manipulation
borkweb
 
PPT
Strutsjspservlet
Sagar Nakul
 
PPT
Struts,Jsp,Servlet
dasguptahirak
 
Microsoft and jQuery
Eric ShangKuan
 
Javascript: Ajax & DOM Manipulation v1.2
borkweb
 
High Performance JavaScript 2011
Nicholas Zakas
 
Developing and testing ajax components
Ignacio Coloma
 
J Query Presentation
Vishal Kumar
 
jQuery and_drupal
BlackCatWeb
 
JWU Guest Talk: JavaScript and AJAX
Hilary Mason
 
Javascript 2009
borkweb
 
Introduction to javaScript
Neil Ghosh
 
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Building Smart Workflows - Dan Diebolt
QuickBase, Inc.
 
Building Complex GUI Apps The Right Way. With Ample SDK - SWDC2010
Sergey Ilinsky
 
High Performance JavaScript (CapitolJS 2011)
Nicholas Zakas
 
Jsfsunum
cagataycivici
 
Even Faster Web Sites at jQuery Conference '09
Steve Souders
 
JavaScript: Ajax & DOM Manipulation
borkweb
 
Strutsjspservlet
Sagar Nakul
 
Struts,Jsp,Servlet
dasguptahirak
 
Ad

Recently uploaded (20)

PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Biography of Daniel Podor.pdf
Daniel Podor
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 

jQuery introduction

  • 1. jQuery Introduction Twitter: @tomijuhola Tomi Juhola, 29.8.2011 Versio: | Status: | Updated: 0.1 Draft Tomi Juhola, 29.8.2011
  • 2. Motivation? Target? jQuery is not much educated technology We have a need with people having JavaScript & jQuery skills, as well as an idea how it should be used Target: Familiarize you with the JavaScript and jQuery library Get to know the mostly used parts of jQuery Give guidance on the first steps towards client-side scripting mastery
  • 3. Agenda JAVASCRIPT BASICS JQUERY BASICS DOM MANIPULATION EVENTS ANIMATIONS JQUERY UI ADDITIONAL RESOURCES
  • 5. What is JavaScript? Scripting language Dynamic (e.g. objects can be extended during run-time) Weakly-typed (No type needed for variables) Multiparadigm: Object-oriented Imperative (statements that change program state) Functional (more mathematical model of imperative programming) Prototype based (uses object cloning instead of inheritance) First-class functions (passing functions as parameters to other functions etc.) Implementation of ECMAScript language standard Used mainly on client-side web interfaces
  • 6. JavaScript syntax JS syntax is C-style, so also close to Java However, JavaScript has really nothing else to do with Java.. Basic statements for ( var i = 0; i < 3; i++ ) { // DO SOMETHING } for ( var i in array) { // DO SOMETHING USEFUL } while ( true ) { // DO SOMETHING FOREVER } If (a == b+2)
  • 7. More simple code examples var variable = ”String”; Variables scoped to the function, not just the block: function isTen(a){ if (a==10) { var result = ”Success!” } return result; }
  • 8. Even more simple code examples var myFirstObject = {name: ”Peter”, age: 12}; myFirstObject.name = ”Pete”; if (myFirstObject.age <18) return ”no fun allowed”; Oh, and how to use? <script type=&quot;text/javascript&quot;> document.write('Hello World!'); </script> <noscript> <p>No JS Support!.</p> </noscript>
  • 9. Issues Cross-browser support DOM (Document Object Model) might be too complicated So HTML page structure No compile time checking No compile time at all :) Can be easily disabled Security: XSS (Cross-site scripting), CSRF (Cross-site request forgery) Not easily testable code
  • 11. What is jQuery? JavaScript library Cross-browser support Aimed for client-side scripting Released in 2006 Most popular JS library today FOSS (Free and Open Source Software) Licensed under MIT license and GPLv2 Under active development, industry support www.jquery.com You’ll only need the jquery-1.2.6.min.js file and one line: <script type=&quot;text/javascript&quot; src=&quot;jquery-1.2.6.min.js“></script> to enable all the goodness!
  • 12. jQuery features DOM elements: select, modify Events CSS handling Flashy effects Ajax Plugin framework Some utility functions (browser version) Very easy to use! And still everything should be cross-browser supported!
  • 14. The Focus of jQuery Thanks to John Resig (JavaScript and jQuery, ACM Northeastern University) jQuery object $ (also valid: jQuery(”div”)… )
  • 15. Examples $(”div”) Selects all divs $(”.myClass”) Selects all items with myClass class $(”#myId”) Selects all items with myId id (should be just one!) $(”div.myClass”) Selects all divs with myClass class $(”div.myClass”).append(”<p>Text text text</p>”); Appends paragrahps to selected divs $(”#myId”).css({font-weight: ”bold”});
  • 16. Test page <!DOCTYPE html> <head> <title>jQuery test</title> </head> <body> <script src=&quot;jquery-1.6.2.min.js&quot;></script> <script> $(document).ready(function(){ $(&quot;.changeMe&quot;).append(&quot;<p>Testing append</p>&quot;); }); </script> <div class=&quot;changeMe&quot;>Text1</div> <div class=&quot;dontChangeMe&quot;>Text2<div> </body> </html> See more at: http://ejohn.org/files/javascript.pdf
  • 18. Examples $(document).ready(function(){ $(&quot;a&quot;). click (function(event){ alert(“You clicked a link, but I won’t let you away&quot;); event.preventDefault(); }); }); $(document).ready(function(){ $(&quot;div&quot;). hover (function () { $(this).append($(&quot;<span> Selected!</span>&quot;)); }, function () { $(this).find(&quot;span:last&quot;).remove(); }); });
  • 19. $.ajax example $.ajax({ url: 'ajax/endpoint', success: function(data) { $('#resultDiv').html(data); alert('DONE!'); } });
  • 21. Animation examples $(document).ready(function(){ $(&quot;a&quot;).click(function(event){ event.preventDefault(); $(this). hide(&quot;slow&quot;); }); }); $(document).ready(function(){ $('div').click(function() { $('#dilbert'). slideToggle ('slow', function() {}); }); });
  • 23. jQuery UI http://jqueryui.com/ Built on top of the jQuery library Includes Widgets Effects Animations All including theme support , cross browser support, styling, internationalization etc.
  • 24. Using e.g. accordion widget <link rel=&quot;stylesheet&quot; href=&quot;themes/base/jquery.ui.all.css&quot;> <script src=&quot;jquery-1.6.2.min.js&quot;></script> <script src=&quot;ui/jquery.ui.core.js&quot;></script> <script src=&quot;ui/jquery.ui.widget.js&quot;></script> <script src=&quot;ui/jquery.ui.accordion.js&quot;></script> ... $(function() { $( &quot;#accordion&quot; ).accordion({ autoHeight: false, navigation: true }); });
  • 26. Web resources http://jquery.com/ http://jqueryui.com/ http://www.w3schools.com/js/default.asp http://www.learningjquery.com/ http://woorkup.com/2011/05/12/jquery-visual-cheat-sheet-1-6/ http://net.tutsplus.com/tutorials/javascript-ajax/simple-draggable-element-persistence-with-jquery/ https://developer.mozilla.org/en/JavaScript
  • 27. Further reading jQuery in Action by Bear Bibeault and Yehida Kayz (Manning) Learning jQuery 1.3 by Jonathan Chaffer and Karl Swedberg (Packt) jQuery Cookbook by Cody Lindley (O’Reilly) jQuery: Novice to Ninja by Earle Castledine and Craig Sharkie (SitePoint) JavaScript, A Beginner’s Guide by John Pollock (McGraw-Hill) JavaScript: The Definitive Guide by David Flanagan (O’Reilly)
  • 28. www.lindorff.fi Thank you! Tomi Juhola Development Lead mobile: +358 44 033 8639 [email_address] www.lindorff.fi Joukahaisenkatu 2 FI-20100 Turku