SlideShare a Scribd company logo
JQuery [1]
 Matteo Magni
jQuery: The Write Less, Do More, JavaScript
                   Library
jQuery
Cos'è?
jQuery è una libreria di funzioni (framework)
javascript, cross-browser per le applicazioni
web, che si propone come obiettivo quello di
semplificare la programmazione lato client
delle pagine HTML. (wikipedia)
Cos'è:            Cosa fa:
• Framework       • Document
• Cross browser     traversing
                  • Event handling
                  • Animating
                  • Ajax interactions
Quindi?
Versioni

            http://jquery.com/
a)PRODUCTION (32KB, Minified and Gzipped)
b)DEVELOPMENT (252KB, Uncompressed Code)

                Differenze?
Production
Pesa solo 32 kb perché è minificata.
http://en.wikipedia.org/wiki/Minification_(programming)


“processo di rimozione di tutti i caratteri non necessari
dal codice sorgente, senza cambiarne la sua
funzionalità.”
Development
252 kb perché scritta in maniera leggibile al
programmatore.
Adatta per la fase di sviluppo, meno per la
produzione per via della banda che occupa.

Le funzionalità di tutte e due sono le stesse
Integrare jQuery
Per integrare jQuery nei nostri progetti basta
includere il file js come javascript esterno.

    <script src="jquery.js"></script>


A quel punto tutte le funzionalità di jQuery ci
saranno disponibili.
Content Delivery Network
E' possibile utilizzare jQuery anche da CDN.
• CDN:Content Delivery Network
  Rete per la consegna di contenuti, cioè
  sistema distribuito di grande estensione
  che attraverso un alto numero di server, il
  quale consente di fornire contenuti agli
  utenti con maggior affidabilità.
CDN
 Vantaggi
 • Far risparmiare banda al
   proprio server
 • L'utente avendola già
   utilizzata protrebbe quindi
   averla già in cache nel
   browser
Google
https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
Microsoft
http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js
jQuery
http://code.jquery.com/jquery-1.8.2.min.js

<script 
src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
Release
Da CDN possiamo vedere che jQuery è
arrivato alla versione 1.8.2 e che quando le
chiamiamo la libreria in quel modo
dobbiamo ricordaci quale vogliamo.
Come usiamo jQuery?
          Il framework jQuery
          definisce una
          variabile jQuery la
          quale contiene un
          oggetto che ha tutti i
          metodi e le proprietà
          implementate dalla
          libreria.
Alias $
jQuery.isNumeric(“­10”);

Ma abbiamo anche a disposizione un alias come
$ che rappresenta la variabile jQuery.

$.isNumeric(“­10”);
Aspettare il DOM
Fino ad ora dovevamo fare una cosa del genere per far partire lo script dopo
il caricamento del documento.
window.onload = function(){ 
  alert("welcome"); 
}


Con jQuery possiamo usare una sintassi di questo tipo
$(document).ready(function(){
   alert("welcome");
 });
Ready vs Load
il codice viene eseguito quando il DOM è pronto ma prima che le immagini
ed altri elementi grafici siano caricati
$(document).ready(function(){
   alert("welcome");
 });


Qui aspetto che tutti gli elementi siano caricati
$(window).load(function(){
   alert("welcome");
 });
Selettori
Attraverso jQuery
possiamo selezionare
tutti gli elementi
presenti nel DOM,
attraverso una sintassi
più semplice che con
Javascript, e poi
andare a manipolarli a
nostro piacimento.
Per elemento - tag
            http://api.jquery.com/element-selector/
<div>DIV1</div>
<div>DIV2</div>
<span>SPAN</span>
<script>
divs = $("div");
alert(divs);
divs.each(function(index) {
alert(index + ': ' + $(this).text());
});
</script>
.each()
Il metodo each() è       Molto importante, la
pensato per eseguire     parola chiave this fa
cicli.                   riferimento ogni volta
Quando viene             ad un elemento
chiamato scandisce gli   diverso del “ciclo”
elementi DOM che
fanno parte
dell'oggetto jQuery.
Per ID
            http://api.jquery.com/id-selector/

<div id=”pippo”>DIV1</div>
<div>DIV2</div>
<span>SPAN</span>
<script>
divs = $("#pippo");
alert(divs.text());
</script>
Per className
             http://api.jquery.com/class-selector/
<div class=”pippo”>DIV1</div>
<div>DIV2</div>
<span class=”pippo”>SPAN</span>
<script>
divs = $(".pippo");
alert(divs.text());
divs.each(function(index) {
alert(index + ': ' + $(this).text());
});
</script>
Per Attributo [name]
Has Attribute Selector [name]
Selects elements that have the specified attribute, with any value.
<div>no id</div>
  <div id="hey">with id</div>
  <div id="there">has an id</div>
  <div>nope</div>
<script>
    $('div[id]').each(function(index) {
       alert(index + ': ' + $(this).text());
    });
</script>
Per attributo [name|="value"]
Attribute Contains Prefix Selector [name|="value"]
Selects elements that have the specified attribute with a value either equal to a given
string or starting with that string followed by a hyphen (-).
<body>
  <a href="example.html" hreflang="en">Some text</a> 
  <a href="example.html" hreflang="en­UK">Some other text</a>
  <a href="example.html" hreflang="english">will not be 
outlined</a>
<script>
$('a[hreflang|="en"]').css('border','3px dotted green');
</script>
Per attributo [name*="value"]
Attribute Contains Selector [name*="value"]
Selects elements that have the specified attribute with a
value containing the a given substring.
<input name="man­news" />
<input name="milkman" />
<input name="letterman2" />
<input name="newmilk" />
<script>$('input[name*="man"]').val('has man 
in it!');</script>
Per attributo [name~="value"]
Attribute Contains Word Selector [name~="value"]
Selects elements that have the specified attribute with a value
containing a given word, delimited by spaces.


 <input name="man­news" />
  <input name="milk man" />
  <input name="letterman2" />
  <input name="newmilk" />
<script>$('input[name~="man"]').val('mr. man is in 
it!');</script>
Per Attributo [name$="value"]
Attribute Ends With Selector [name$="value"]
Selects elements that have the specified attribute with a
value ending exactly with a given string. The comparison is
case sensitive.
<input name="newsletter" />
  <input name="milkman" />
  <input name="jobletter" />
<script>$('input[name$="letter"]').val('a 
letter');</script>
Per Attributo [name="value"]
Attribute Equals Selector [name="value"]
Selects elements that have the specified attribute with a value exactly equal to a
certain value.
      <input type="radio" name="newsletter" value="Hot Fuzz" />
      <span>name?</span>
      <input type="radio" name="newsletter" value="Cold Fusion" 
/>
      <span>value?</span>
      <input type="radio" name="newsletter" value="Evil 
Plans" />
      <span>value?</span>
<script>$('input[value="Hot Fuzz"]').next().text(" Hot 
Fuzz");</script>
Per attributo [name!="value"]
Attribute Not Equal Selector [name!="value"]
Select elements that either don't have the specified attribute, or do have the
specified attribute but not with a certain value.
   <input type="radio" name="newsletter" value="Hot Fuzz" />
    <span>name is newsletter</span>
    <input type="radio" value="Cold Fusion" />
    <span>no name</span>
    <input type="radio" name="accept" value="Evil Plans" />
    <span>name is accept</span>
  </div>
<script>$('input[name!="newsletter"]').next().append('<b>; not 
newsletter</b>');</script>
Per Attributo [name^="value"]
Attribute Starts With Selector [name^="value"]
Selects elements that have the specified attribute with a
value beginning exactly with a given string.
  <input name="newsletter" />
  <input name="milkman" />
  <input name="newsboy" />
<script>$('input[name^="news"]').val('news 
here!');</script>
Domande?

               Slide:
http://www.slideshare.net/ilbonzo
               Code:
https://github.com/ilbonzo/Cypher
                mail:
        matteo@magni.me

More Related Content

PDF
jQuery - 1 | WebMaster & WebDesigner
PPT
E suap - tecnologie client
PDF
JavaScript
PDF
Mantenere una distribuzione Drupal attraverso test coverage: Paddle case study
PDF
Javascript - 4 | WebMaster & WebDesigner
PDF
Corso avanzato di Tecnologie WEB - jquery e d3js
PPTX
Angular js: routing
PPTX
AngularJS: server communication
jQuery - 1 | WebMaster & WebDesigner
E suap - tecnologie client
JavaScript
Mantenere una distribuzione Drupal attraverso test coverage: Paddle case study
Javascript - 4 | WebMaster & WebDesigner
Corso avanzato di Tecnologie WEB - jquery e d3js
Angular js: routing
AngularJS: server communication

What's hot (20)

KEY
Progetto su iPhone - Seminario di Reti Wireless
PDF
Introduzione a node.js
PDF
AngularJS-Intro
PDF
ZoeFX: un framework MVC per JavaFX
PPTX
ODP
Ubuntu Touch: Sviluppo App e Convergenza
PPTX
Write less do more...with jQuery
PPTX
m-v-vm @ UgiAlt.Net
PDF
Angularjs
ODP
Corso angular js componenti
PDF
Ajax e jQuery
PDF
Javascript - 4 | WebMaster & WebDesigner
PPTX
PPTX
Entity Framework 4 vs NHibernate 3
PPTX
Entity Framework 6 for developers, Code-First!
PDF
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
PDF
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
PDF
Php mysql3
PPTX
AngularJS: accessibility
PPTX
Usare Knockout JS
Progetto su iPhone - Seminario di Reti Wireless
Introduzione a node.js
AngularJS-Intro
ZoeFX: un framework MVC per JavaFX
Ubuntu Touch: Sviluppo App e Convergenza
Write less do more...with jQuery
m-v-vm @ UgiAlt.Net
Angularjs
Corso angular js componenti
Ajax e jQuery
Javascript - 4 | WebMaster & WebDesigner
Entity Framework 4 vs NHibernate 3
Entity Framework 6 for developers, Code-First!
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Come sfruttare tutte le potenzialità di Symfony in Drupal 8
Php mysql3
AngularJS: accessibility
Usare Knockout JS
Ad

Viewers also liked (11)

PDF
Html e Css - 1 | WebMaster & WebDesigner
PDF
Javascript - 1 | WebMaster & WebDesigner
PDF
follow-ap DAY 4: HTML5 e jQuery
PDF
Francesco Inguscio - Avviare una start-up
PDF
Francesco Inguscio - Start-up financing from the side of the entrepreneur
PDF
Web Usability - 1 | WebMaster & WebDesigner
PDF
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene
PDF
jQuery - 2 | WebMaster & WebDesigner
PDF
Gianfrasoft Corso Di Php Parte 1
PPT
Introduzione al linguaggio PHP
PDF
PHP: programmi gestionali, introduzione
Html e Css - 1 | WebMaster & WebDesigner
Javascript - 1 | WebMaster & WebDesigner
follow-ap DAY 4: HTML5 e jQuery
Francesco Inguscio - Avviare una start-up
Francesco Inguscio - Start-up financing from the side of the entrepreneur
Web Usability - 1 | WebMaster & WebDesigner
[F5 Hit Refresh] Pierpaolo Basile - Accesso alle informazioni con apache lucene
jQuery - 2 | WebMaster & WebDesigner
Gianfrasoft Corso Di Php Parte 1
Introduzione al linguaggio PHP
PHP: programmi gestionali, introduzione
Ad

Similar to jQuery - 1 | WebMaster & WebDesigner (20)

PDF
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
PPTX
Matteo Bicocchi - Introducing HTML5
PPTX
AngularJS – Reinventare le applicazioni web
PDF
September 2010 - Gatein
PPT
#dd12 grillo daniele_xpages_tips_tricks_rev2
PPT
Introduzione a jQuery
PDF
DDive - 8.5.2 Xpages - L'evoluzione continua
PDF
MongoDB User Group Padova - Overviews iniziale su MongoDB
PPT
XPages Tips & Tricks, #dd13
PDF
Node.js - Server Side Javascript
PDF
Tech Webinar: Test e2e per AngularJS e non solo
PPTX
Le novita di visual studio 2012
PDF
Sviluppo web con Ruby on Rails
PDF
Corso Javascript
PDF
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...
PDF
react-it.pdf
ODP
Drupal Day 2012 - DRUPAL 8: I CAMBIAMENTI CHE CI ASPETTANO
PDF
Luca Masini: Introduzione a GWT 2.0
PDF
Corso WebApp iOS - Lezione 06: Web Development for iOS Devices
Matteo Bicocchi - Introducing HTML5
AngularJS – Reinventare le applicazioni web
September 2010 - Gatein
#dd12 grillo daniele_xpages_tips_tricks_rev2
Introduzione a jQuery
DDive - 8.5.2 Xpages - L'evoluzione continua
MongoDB User Group Padova - Overviews iniziale su MongoDB
XPages Tips & Tricks, #dd13
Node.js - Server Side Javascript
Tech Webinar: Test e2e per AngularJS e non solo
Le novita di visual studio 2012
Sviluppo web con Ruby on Rails
Corso Javascript
Tech Webinar: Advanced AngularJS, tecniche avanzate per padroneggiare il fram...
react-it.pdf
Drupal Day 2012 - DRUPAL 8: I CAMBIAMENTI CHE CI ASPETTANO
Luca Masini: Introduzione a GWT 2.0

More from Matteo Magni (20)

PDF
Introduzione DevOps con Ansible
PDF
HTML5 e Css3 - 7 | WebMaster & WebDesigner
PDF
HTML5 e Css3 - 6 | WebMaster & WebDesigner
PDF
HTML5 e Css3 - 5 | WebMaster & WebDesigner
PDF
HTML5 e Css3 - 4 | WebMaster & WebDesigner
PDF
HTML5 e Css3 - 3 | WebMaster & WebDesigner
PDF
HTML5 e Css3 - 2 | WebMaster & WebDesigner
PDF
HTML5 e Css3 - 1 | WebMaster & WebDesigner
PDF
jQuery - 5 | WebMaster & WebDesigner
PDF
jQuery - 4 | WebMaster & WebDesigner
PDF
jQuery - 3 | WebMaster & WebDesigner
PDF
jQuery - 2 | WebMaster & WebDesigner
PDF
Javascript - 7 | WebMaster & WebDesigner
PDF
Javascript - 6 | WebMaster & WebDesigner
PDF
Javascript - 5 | WebMaster & WebDesigner
PDF
Javascript - 3 | WebMaster & WebDesigner
PDF
Javascript - 2 | WebMaster & WebDesigner
PDF
Web Usability - 3 | WebMaster & WebDesigner
PDF
Web Usability - 2 | WebMaster & WebDesigner
PDF
Seo e Web Marketing - 5 | WebMaster & WebDesigner
Introduzione DevOps con Ansible
HTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 6 | WebMaster & WebDesigner
HTML5 e Css3 - 5 | WebMaster & WebDesigner
HTML5 e Css3 - 4 | WebMaster & WebDesigner
HTML5 e Css3 - 3 | WebMaster & WebDesigner
HTML5 e Css3 - 2 | WebMaster & WebDesigner
HTML5 e Css3 - 1 | WebMaster & WebDesigner
jQuery - 5 | WebMaster & WebDesigner
jQuery - 4 | WebMaster & WebDesigner
jQuery - 3 | WebMaster & WebDesigner
jQuery - 2 | WebMaster & WebDesigner
Javascript - 7 | WebMaster & WebDesigner
Javascript - 6 | WebMaster & WebDesigner
Javascript - 5 | WebMaster & WebDesigner
Javascript - 3 | WebMaster & WebDesigner
Javascript - 2 | WebMaster & WebDesigner
Web Usability - 3 | WebMaster & WebDesigner
Web Usability - 2 | WebMaster & WebDesigner
Seo e Web Marketing - 5 | WebMaster & WebDesigner

jQuery - 1 | WebMaster & WebDesigner

  • 2. jQuery: The Write Less, Do More, JavaScript Library
  • 4. Cos'è? jQuery è una libreria di funzioni (framework) javascript, cross-browser per le applicazioni web, che si propone come obiettivo quello di semplificare la programmazione lato client delle pagine HTML. (wikipedia)
  • 5. Cos'è: Cosa fa: • Framework • Document • Cross browser traversing • Event handling • Animating • Ajax interactions
  • 7. Versioni http://jquery.com/ a)PRODUCTION (32KB, Minified and Gzipped) b)DEVELOPMENT (252KB, Uncompressed Code) Differenze?
  • 8. Production Pesa solo 32 kb perché è minificata. http://en.wikipedia.org/wiki/Minification_(programming) “processo di rimozione di tutti i caratteri non necessari dal codice sorgente, senza cambiarne la sua funzionalità.”
  • 9. Development 252 kb perché scritta in maniera leggibile al programmatore. Adatta per la fase di sviluppo, meno per la produzione per via della banda che occupa. Le funzionalità di tutte e due sono le stesse
  • 10. Integrare jQuery Per integrare jQuery nei nostri progetti basta includere il file js come javascript esterno. <script src="jquery.js"></script> A quel punto tutte le funzionalità di jQuery ci saranno disponibili.
  • 11. Content Delivery Network E' possibile utilizzare jQuery anche da CDN. • CDN:Content Delivery Network Rete per la consegna di contenuti, cioè sistema distribuito di grande estensione che attraverso un alto numero di server, il quale consente di fornire contenuti agli utenti con maggior affidabilità.
  • 12. CDN Vantaggi • Far risparmiare banda al proprio server • L'utente avendola già utilizzata protrebbe quindi averla già in cache nel browser
  • 14. Release Da CDN possiamo vedere che jQuery è arrivato alla versione 1.8.2 e che quando le chiamiamo la libreria in quel modo dobbiamo ricordaci quale vogliamo.
  • 15. Come usiamo jQuery? Il framework jQuery definisce una variabile jQuery la quale contiene un oggetto che ha tutti i metodi e le proprietà implementate dalla libreria.
  • 16. Alias $ jQuery.isNumeric(“­10”); Ma abbiamo anche a disposizione un alias come $ che rappresenta la variabile jQuery. $.isNumeric(“­10”);
  • 17. Aspettare il DOM Fino ad ora dovevamo fare una cosa del genere per far partire lo script dopo il caricamento del documento. window.onload = function(){    alert("welcome");  } Con jQuery possiamo usare una sintassi di questo tipo $(document).ready(function(){    alert("welcome");  });
  • 18. Ready vs Load il codice viene eseguito quando il DOM è pronto ma prima che le immagini ed altri elementi grafici siano caricati $(document).ready(function(){    alert("welcome");  }); Qui aspetto che tutti gli elementi siano caricati $(window).load(function(){    alert("welcome");  });
  • 19. Selettori Attraverso jQuery possiamo selezionare tutti gli elementi presenti nel DOM, attraverso una sintassi più semplice che con Javascript, e poi andare a manipolarli a nostro piacimento.
  • 20. Per elemento - tag http://api.jquery.com/element-selector/ <div>DIV1</div> <div>DIV2</div> <span>SPAN</span> <script> divs = $("div"); alert(divs); divs.each(function(index) { alert(index + ': ' + $(this).text()); }); </script>
  • 21. .each() Il metodo each() è Molto importante, la pensato per eseguire parola chiave this fa cicli. riferimento ogni volta Quando viene ad un elemento chiamato scandisce gli diverso del “ciclo” elementi DOM che fanno parte dell'oggetto jQuery.
  • 22. Per ID http://api.jquery.com/id-selector/ <div id=”pippo”>DIV1</div> <div>DIV2</div> <span>SPAN</span> <script> divs = $("#pippo"); alert(divs.text()); </script>
  • 23. Per className http://api.jquery.com/class-selector/ <div class=”pippo”>DIV1</div> <div>DIV2</div> <span class=”pippo”>SPAN</span> <script> divs = $(".pippo"); alert(divs.text()); divs.each(function(index) { alert(index + ': ' + $(this).text()); }); </script>
  • 24. Per Attributo [name] Has Attribute Selector [name] Selects elements that have the specified attribute, with any value. <div>no id</div>   <div id="hey">with id</div>   <div id="there">has an id</div>   <div>nope</div> <script>     $('div[id]').each(function(index) {        alert(index + ': ' + $(this).text());     }); </script>
  • 25. Per attributo [name|="value"] Attribute Contains Prefix Selector [name|="value"] Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-). <body>   <a href="example.html" hreflang="en">Some text</a>    <a href="example.html" hreflang="en­UK">Some other text</a>   <a href="example.html" hreflang="english">will not be  outlined</a> <script> $('a[hreflang|="en"]').css('border','3px dotted green'); </script>
  • 26. Per attributo [name*="value"] Attribute Contains Selector [name*="value"] Selects elements that have the specified attribute with a value containing the a given substring. <input name="man­news" /> <input name="milkman" /> <input name="letterman2" /> <input name="newmilk" /> <script>$('input[name*="man"]').val('has man  in it!');</script>
  • 27. Per attributo [name~="value"] Attribute Contains Word Selector [name~="value"] Selects elements that have the specified attribute with a value containing a given word, delimited by spaces.  <input name="man­news" />   <input name="milk man" />   <input name="letterman2" />   <input name="newmilk" /> <script>$('input[name~="man"]').val('mr. man is in  it!');</script>
  • 28. Per Attributo [name$="value"] Attribute Ends With Selector [name$="value"] Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive. <input name="newsletter" />   <input name="milkman" />   <input name="jobletter" /> <script>$('input[name$="letter"]').val('a  letter');</script>
  • 29. Per Attributo [name="value"] Attribute Equals Selector [name="value"] Selects elements that have the specified attribute with a value exactly equal to a certain value.       <input type="radio" name="newsletter" value="Hot Fuzz" />       <span>name?</span>       <input type="radio" name="newsletter" value="Cold Fusion"  />       <span>value?</span>       <input type="radio" name="newsletter" value="Evil  Plans" />       <span>value?</span> <script>$('input[value="Hot Fuzz"]').next().text(" Hot  Fuzz");</script>
  • 30. Per attributo [name!="value"] Attribute Not Equal Selector [name!="value"] Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value.    <input type="radio" name="newsletter" value="Hot Fuzz" />     <span>name is newsletter</span>     <input type="radio" value="Cold Fusion" />     <span>no name</span>     <input type="radio" name="accept" value="Evil Plans" />     <span>name is accept</span>   </div> <script>$('input[name!="newsletter"]').next().append('<b>; not  newsletter</b>');</script>
  • 31. Per Attributo [name^="value"] Attribute Starts With Selector [name^="value"] Selects elements that have the specified attribute with a value beginning exactly with a given string.   <input name="newsletter" />   <input name="milkman" />   <input name="newsboy" /> <script>$('input[name^="news"]').val('news  here!');</script>
  • 32. Domande? Slide: http://www.slideshare.net/ilbonzo Code: https://github.com/ilbonzo/Cypher mail: matteo@magni.me