SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
Website Construction
Client-side programming with JQuery



     Frédéric Haziza <daz@it.uu.se>


            Department of Computer Systems
                         Uppsala University




                          Summer 2009
JavaScript allows developers to




                           create rich and interactive web interfaces

         establish asynchronous communication with servers for constantly
                      up-to-date data without a page refresh.




2   WebConst’09 | Website Construction (Client-side programming with JQuery)
Javascript




                                                      tutorial




3   WebConst’09 | Website Construction (Client-side programming with JQuery)
Javascript library



                                          Write less, do more.

           JQuery / JQuery UI
           MooTools
           Scriptaculous / Prototype                                           Element selection
           Dojo                                                                DOM manipulation
           Yahoo! UI Library (YUI)                                             AJAX
           MochiKit
           ... ?? ...



4   WebConst’09 | Website Construction (Client-side programming with JQuery)
Loading jQuery

       <html>
         <head>
           ...
           < s c r i p t t y p e=" t e x t / j a v a s c r i p t "
                         s r c=" p a t h / t o / j q u e r y . j s "></ s c r i p t>
           ...
           < s c r i p t t y p e=" t e x t / j a v a s c r i p t ">
               // Your c o d e h e r e
           </ s c r i p t>

           </ head>

         <body>
            <!−− y o u r c o n t e n t −−>
         </ body>
       </ html>


5   WebConst’09 | Website Construction (Client-side programming with JQuery)
Usally, most programmers end up testing:


       <html>
         <head>
            ...
            < s c r i p t t y p e=" t e x t / j a v a s c r i p t ">
                 window . o n l o a d = f u n c t i o n ( ) {
                                a l e r t ( ’ Hello world ! ’ ) ;
                            }
            </ s c r i p t>
         </ head>
         <body>
            <!−− y o u r c o n t e n t −−>
         </ body>
       </ html>




6   WebConst’09 | Website Construction (Client-side programming with JQuery)
Loading jQuery


       <html>
         <head>
           ...
           < s c r i p t t y p e=" t e x t / j a v a s c r i p t "
                         s r c=" p a t h / t o / j q u e r y . j s "></ s c r i p t>
           ...
           < s c r i p t t y p e=" t e x t / j a v a s c r i p t "
                         s r c = ’ ’ mycode . j s ’ ’></ s c r i p t>

         </ head>
         <body>
            <!−− y o u r c o n t e n t −−>
         </ body>
       </ html>




7   WebConst’09 | Website Construction (Client-side programming with JQuery)
Saving bandwidth




       Instead of loading from your own server, get it from google.

       http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

                                            Readable      Non-readable




8   WebConst’09 | Website Construction (Client-side programming with JQuery)
JQuery - Documentation




                                                    Homepage

                                                   Online docs




9   WebConst’09 | Website Construction (Client-side programming with JQuery)
Old style
       <script type="text/javascript">

        function notEmpty(){

             var myTextField = document.getElementById(’myText’);
             if(myTextField.value != "")
                alert("You entered: " + myTextField.value)
             else
                alert("Would you please enter some text?")
        }

       </script>

       <input type=’text’ id=’myText’ />
       <input type=’button’
              value=’Form Checker’ />
              onclick=’notEmpty()’ />



10   WebConst’09 | Website Construction (Client-side programming with JQuery)
Simple with JQuery


       Problem
       Need to wait for the document to be ready

       Solution
       JQuery: Event handler waits for the document to be ready.

       $(document).ready(function() {
           // do stuff when DOM is ready
       });

                                               What is the DOM?




11   WebConst’09 | Website Construction (Client-side programming with JQuery)
Example
       HTML
       <a href=’’http://jquery .com’’>Visit Us</a>

       JQuery
       $ ( document ) . r e a d y ( f u n c t i o n ( ) {

          $( "a" ) . c l i c k ( f u n c t i o n ( ) {
             a l e r t ( " Hello world ! " ) ;
          }) ;

       }) ;


       $(“a”) selects all a elements.
       This code binds a click event to all selected elements (in this case,
       a single anchor element) and executes the provided function when
       the event occurs.
12   WebConst’09 | Website Construction (Client-side programming with JQuery)
The magic $


       $(’a’);
       All anchors in the document (CSS/XPath)

       $(’div.container’);
       All divs with a container class (CSS)

       $(’div[@class=codeSnippet]/code’);
       All code elements that are direct children of divs in the document
       with the class ’codeSnippet’. (XPath)

       As of version 1.2, XPath syntax has been separated out in its own
       plugin (reducing the footprint, i.e smaller file size)

13   WebConst’09 | Website Construction (Client-side programming with JQuery)
The magic $




       $( selector, [context] );

       The selector can be a CSS selector or an XPath query. The context
       limits the scope of the search. Note that it returns an object which
       represent all matching elements.
                                                 JQuery selectors




14   WebConst’09 | Website Construction (Client-side programming with JQuery)
JQuery Effects




                                                  JQuery effects

                                                   online demo




15   WebConst’09 | Website Construction (Client-side programming with JQuery)

Contenu connexe

Tendances

Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentation
Scott Messinger
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
jasonsich
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.js
Soós Gábor
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig
 

Tendances (20)

JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery Templates
 
Vue.js for beginners
Vue.js for beginnersVue.js for beginners
Vue.js for beginners
 
KnockoutJS and MVVM
KnockoutJS and MVVMKnockoutJS and MVVM
KnockoutJS and MVVM
 
22 j query1
22 j query122 j query1
22 j query1
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentation
 
JQuery Comprehensive Overview
JQuery Comprehensive OverviewJQuery Comprehensive Overview
JQuery Comprehensive Overview
 
Java script
Java scriptJava script
Java script
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Web Components: The future of Web Application Development
Web Components: The future of Web Application DevelopmentWeb Components: The future of Web Application Development
Web Components: The future of Web Application Development
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.js
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 

Similaire à handout-05b

03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuery
crgwbr
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
george.james
 
01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
Tommy Vercety
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 

Similaire à handout-05b (20)

03 Web Events and jQuery
03 Web Events and jQuery03 Web Events and jQuery
03 Web Events and jQuery
 
JavaScript front end performance optimizations
JavaScript front end performance optimizationsJavaScript front end performance optimizations
JavaScript front end performance optimizations
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
Intro to jQuery @ Startup Institute
Intro to jQuery @ Startup InstituteIntro to jQuery @ Startup Institute
Intro to jQuery @ Startup Institute
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
 
The WebView Role in Hybrid Applications
The WebView Role in Hybrid ApplicationsThe WebView Role in Hybrid Applications
The WebView Role in Hybrid Applications
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform better
 
01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Hybrid apps - Your own mini Cordova
Hybrid apps - Your own mini CordovaHybrid apps - Your own mini Cordova
Hybrid apps - Your own mini Cordova
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
Introduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint WorkshopIntroduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint Workshop
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
Gdg dev fest hybrid apps your own mini-cordova
Gdg dev fest hybrid apps  your own mini-cordovaGdg dev fest hybrid apps  your own mini-cordova
Gdg dev fest hybrid apps your own mini-cordova
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Javascript ui for rest services
Javascript ui for rest servicesJavascript ui for rest services
Javascript ui for rest services
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 

Plus de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

Plus de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Dernier

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Dernier (20)

SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Buy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptxBuy Epson EcoTank L3210 Colour Printer Online.pptx
Buy Epson EcoTank L3210 Colour Printer Online.pptx
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 

handout-05b

  • 1. Website Construction Client-side programming with JQuery Frédéric Haziza <daz@it.uu.se> Department of Computer Systems Uppsala University Summer 2009
  • 2. JavaScript allows developers to create rich and interactive web interfaces establish asynchronous communication with servers for constantly up-to-date data without a page refresh. 2 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 3. Javascript tutorial 3 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 4. Javascript library Write less, do more. JQuery / JQuery UI MooTools Scriptaculous / Prototype Element selection Dojo DOM manipulation Yahoo! UI Library (YUI) AJAX MochiKit ... ?? ... 4 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 5. Loading jQuery <html> <head> ... < s c r i p t t y p e=" t e x t / j a v a s c r i p t " s r c=" p a t h / t o / j q u e r y . j s "></ s c r i p t> ... < s c r i p t t y p e=" t e x t / j a v a s c r i p t "> // Your c o d e h e r e </ s c r i p t> </ head> <body> <!−− y o u r c o n t e n t −−> </ body> </ html> 5 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 6. Usally, most programmers end up testing: <html> <head> ... < s c r i p t t y p e=" t e x t / j a v a s c r i p t "> window . o n l o a d = f u n c t i o n ( ) { a l e r t ( ’ Hello world ! ’ ) ; } </ s c r i p t> </ head> <body> <!−− y o u r c o n t e n t −−> </ body> </ html> 6 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 7. Loading jQuery <html> <head> ... < s c r i p t t y p e=" t e x t / j a v a s c r i p t " s r c=" p a t h / t o / j q u e r y . j s "></ s c r i p t> ... < s c r i p t t y p e=" t e x t / j a v a s c r i p t " s r c = ’ ’ mycode . j s ’ ’></ s c r i p t> </ head> <body> <!−− y o u r c o n t e n t −−> </ body> </ html> 7 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 8. Saving bandwidth Instead of loading from your own server, get it from google. http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js Readable Non-readable 8 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 9. JQuery - Documentation Homepage Online docs 9 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 10. Old style <script type="text/javascript"> function notEmpty(){ var myTextField = document.getElementById(’myText’); if(myTextField.value != "") alert("You entered: " + myTextField.value) else alert("Would you please enter some text?") } </script> <input type=’text’ id=’myText’ /> <input type=’button’ value=’Form Checker’ /> onclick=’notEmpty()’ /> 10 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 11. Simple with JQuery Problem Need to wait for the document to be ready Solution JQuery: Event handler waits for the document to be ready. $(document).ready(function() { // do stuff when DOM is ready }); What is the DOM? 11 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 12. Example HTML <a href=’’http://jquery .com’’>Visit Us</a> JQuery $ ( document ) . r e a d y ( f u n c t i o n ( ) { $( "a" ) . c l i c k ( f u n c t i o n ( ) { a l e r t ( " Hello world ! " ) ; }) ; }) ; $(“a”) selects all a elements. This code binds a click event to all selected elements (in this case, a single anchor element) and executes the provided function when the event occurs. 12 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 13. The magic $ $(’a’); All anchors in the document (CSS/XPath) $(’div.container’); All divs with a container class (CSS) $(’div[@class=codeSnippet]/code’); All code elements that are direct children of divs in the document with the class ’codeSnippet’. (XPath) As of version 1.2, XPath syntax has been separated out in its own plugin (reducing the footprint, i.e smaller file size) 13 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 14. The magic $ $( selector, [context] ); The selector can be a CSS selector or an XPath query. The context limits the scope of the search. Note that it returns an object which represent all matching elements. JQuery selectors 14 WebConst’09 | Website Construction (Client-side programming with JQuery)
  • 15. JQuery Effects JQuery effects online demo 15 WebConst’09 | Website Construction (Client-side programming with JQuery)