SlideShare a Scribd company logo
jQuery
Introduction to using jQuery
ugo.rinaldi@gmail.com
jQuery
• jQuery is a lightweight, "write less, do more", JavaScript
library.
• The purpose of jQuery is to make it much easier to use
JavaScript on your website.
• jQuery takes a lot of common tasks that require many
lines of JavaScript code to accomplish, and wraps them
into methods that you can call with a single line of code.
• jQuery also simplifies a lot of the complicated things
from JavaScript, like AJAX calls and DOM manipulation.
Features
The jQuery library contains the following features:
 HTML/DOM manipulation
 CSS manipulation
 HTML event methods
 Effects and animations
 AJAX
 Utilities
 jQuery will run exactly the same in all major browsers,
including Internet Explorer 6!
There are several ways to start using jQuery on your web
site. You can:
 Download the jQuery library from jQuery.com
 Include jQuery from a CDN, like Google
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.
min.js"> </script>
</head>
Adding jQuery
 The jQuery syntax is tailor made for selecting HTML elements and
performing some action on the element(s).
 Basic syntax is: $(selector).action()
 A $ sign to define/access jQuery
 A (selector) to "query (or find)" HTML elements
 A jQuery action() to be performed on the element(s)
 Examples:
 $(this).hide() - hides the current element.
 $("p").hide() - hides all <p> elements.
 $(".test").hide() - hides all elements with class="test".
 $("#test").hide() - hides the element with id="test".
jQuery Syntax
 $("*") Selects all elements
 $(this) Selects the current HTML element
 $("p.intro") Selects all <p> elements with class="intro"
 $("p:first") Selects the first <p> element
 $("ul li:first") Selects the first <li> element of the first <ul>
 $("ul li:first-child") Selects the first <li> element of every <ul>
 $("[href]") Selects all elements with an href attribute
 $("a[target='_blank']") Selects all <a> elements with a target attribute value equal to
"_blank"
 $("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal
to "_blank"
 $(":button") Selects all <button> elements and <input> elements of type="button"
 $("tr:even") Selects all even <tr> elements
 $("tr:odd") Selects all odd <tr> elements
jQuery selectors like CSS syntax
 All the different visitor's actions that a web page can
respond to, are called events.
 An event represents the precise moment when
something happens.
Examples:
 moving a mouse over an element
 selecting a radio button
 clicking on an element
Events
• $(document).ready(function(){
// Insert one of the following event functions
});
• $("p").click(function(){ …});
• $("p").dblclick(function(){ …});
• $("p").mouseenter(function(){ //when mouse pointer enters});
• $("p").mouseleave(function(){//when mouse pointer leaves});
• $("p").mousedown(function(){//when click + over});
• $("p").mouseup(function(){//when release + over});
●
$("#p1").hover(
function(){ alert("You entered p1!");},
function(){ alert("Bye! You now leave p1!"); }
);
Examples
 $("p").on({
focus: function(){
$(this).css("background-color", "lightgray");
},
blur: function(){
$(this).css("background-color", "lightblue");
},
click: function(){
$(this).css("background-color", "yellow");
}
});
Attach event handlers to elements
Effects hide, show, fade
 $("#hide").click(function(){
$("p").hide(); // $("p").hide(1000);
});
 $("p").show();
 $("p").toggle();
 $(“p”).fadeIn(”slow”,callback function);
 $(“p”).fadeOut(”fast”,callback function);
 $(“p”).fadeToggle(1500,callback function);
 $(“p”).fadeTo(”fast”,0.5,callback function);
 With jQuery you can create a sliding effect on elements.
 jQuery has the following slide methods:
 slideDown()
 slideUp()
 slideToggle()
 Syntax:
 $(selector).method(speed,callback);
jQuery Sliding Methods
 $("button").click(function(){
$("div").animate({ left: '250px‘, opacity: '0.5‘, height: '150px‘, width: ‘+=5px’ });
});
 $("button").click(function(){
var div = $("div");
div.animate({height: '300px', opacity: '0.4'}, "slow");
div.animate({width: '300px', opacity: '0.8'}, "slow");
div.animate({height: '100px', opacity: '0.4'}, "slow");
div.animate({width: '100px', opacity: '0.8'}, "slow");
});
 $("div").animate({
height: 'toggle’ });
 $("#stop").click(function(){
$("#panel").stop(); // interrompe un’animazione
});
Animation
 A callback function is executed after the current effect is 100%
finished.
$("button").click(function(){
$("p").hide("slow", function(){
alert("The paragraph is now hidden");
});
});
 $("button").click(function(){
$("p").hide(1000);
alert("The paragraph is now hidden");
});
Callback function
 $("#p1").css("color",
"red").slideUp(2000).slideDown(2000);
 Si può scrivere anche
$("#p1").css("color", "red")
.slideUp(2000)
.slideDown(2000);
Method chaining
Simple, but useful, jQuery methods for DOM
manipulation/examine are:
 text() - Sets or returns the text content of
selected elements
 html() - Sets or returns the content of selected
elements (including HTML markup)
 val() - Sets or returns the value of form fields
 attr() – Gets attribute value
DOM manipulation
 // per leggere
 $("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
 // per scrivere; unico metodo che richiede 2 parametri
 $("button").click(function(){
$("#w3s").attr("href", "http://www.w3schools.com/jquery");
});
 $("button").click(function(){
$("#w3s").attr({
"href" : "http://www.w3schools.com/jquery",
"title" : "W3Schools jQuery Tutorial"
});
});
Esempi
 $("p").css("background-color");
 $("p").css("background-color", "yellow");
 $("p").css({"background-color": "yellow", "font-
size": "200%"});
css() Method
Dimensions
 $("button").click(function(){
var txt = "";
txt += "Width: " + $("#div1").width() + "</br>";
txt += "Height: " + $("#div1").height();
$("#div1").html(txt);
});
 $("button").click(function(){
var txt = "";
txt += "Document width/height: " + $(document).width();
txt += "x" + $(document).height() + "n";
txt += "Window width/height: " + $(window).width();
txt += "x" + $(window).height();
alert(txt);
});
 $("button").click(function(){
$("#div1").width(500).height(500);
});// per settare insieme widht & height
…
 AJAX = Asynchronous JavaScript and XML.
 In short: AJAX is about loading data in the
background and display it on the webpage,
without reloading the whole page.
Ajax
load()
 Syntax:
$(selector).load(URL,data,callback(response,status,xhr));
 $(“#btn1”).click(function(){$
("#div1").load("demo.txt"});
 Esempio
AJAX get() and post() Methods
 The jQuery get() and post() methods are used to request data from the server with an HTTP request.
 Syntax:
$.get(URL,callback(data, status));
$.post(URL,data,callback);
Esempi:
$("#btn1").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "nStatus: " + status);
});
});
$("button").click(function(){
$.post("demo_test_post.asp",
{ name: "Donald Duck",
city: "Duckburg" },
function(data, status){
alert("Data: " + data + "nStatus: " + status); });
});
Esempi e sitografia
Qui puoi trovare esempi utili
Qui puoi trovare l'intero tutorial ed una Refer
ences Guide
http://www.w3schools.com

More Related Content

What's hot

Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
Simon Willison
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
NexThoughts Technologies
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
manugoel2003
 
J Query Public
J Query PublicJ Query Public
J Query Public
pradeepsilamkoti
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
Sudar Muthu
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
Rafael Felix da Silva
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
Stijn Van Minnebruggen
 
jQuery
jQueryjQuery
jQuery
jQueryjQuery
jQuery
Jay Poojara
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
musrath mohammad
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell
 
jQuery
jQueryjQuery
jQuery
Vishwa Mohan
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory management
Adrian Cardenas
 
Php mysql
Php mysqlPhp mysql
Php mysql
Manish Jain
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
WebStackAcademy
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
Gil Fink
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
Kaloyan Kosev
 
jQuery
jQueryjQuery

What's hot (20)

Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
J Query Public
J Query PublicJ Query Public
J Query Public
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
jQuery
jQueryjQuery
jQuery
 
jQuery
jQueryjQuery
jQuery
 
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
jQuery
jQueryjQuery
jQuery
 
J query training
J query trainingJ query training
J query training
 
Iterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory managementIterators & generators: practical uses in memory management
Iterators & generators: practical uses in memory management
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
jQuery - Chapter 5 - Ajax
jQuery - Chapter 5 -  AjaxjQuery - Chapter 5 -  Ajax
jQuery - Chapter 5 - Ajax
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJS
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
jQuery
jQueryjQuery
jQuery
 

Similar to Introduzione JQuery

Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Seble Nigussie
 
jQuery
jQueryjQuery
JQuery
JQueryJQuery
JQuery
DevTalk
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
AditiPawale1
 
J query
J queryJ query
J query
Manav Prasad
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
AnamikaRai59
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
James Johnson
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
azz71
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
Allegient
 
Introduction to jQuery - The basics
Introduction to jQuery - The basicsIntroduction to jQuery - The basics
Introduction to jQuery - The basics
Maher Hossain
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
James Johnson
 
jQuery besic
jQuery besicjQuery besic
jQuery besic
Syeful Islam
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Gunjan Kumar
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
kolkatageeks
 
JQuery Overview
JQuery OverviewJQuery Overview
JQuery Overview
Mahmoud Tolba
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQueryLaila Buncab
 

Similar to Introduzione JQuery (20)

Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery
jQueryjQuery
jQuery
 
JQuery
JQueryJQuery
JQuery
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
J query
J queryJ query
J query
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
 
jQuery Rescue Adventure
jQuery Rescue AdventurejQuery Rescue Adventure
jQuery Rescue Adventure
 
Introduction to jQuery - The basics
Introduction to jQuery - The basicsIntroduction to jQuery - The basics
Introduction to jQuery - The basics
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
 
jQuery besic
jQuery besicjQuery besic
jQuery besic
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
How to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQueryHow to increase Performance of Web Application using JQuery
How to increase Performance of Web Application using JQuery
 
Jquery 3
Jquery 3Jquery 3
Jquery 3
 
JQuery Overview
JQuery OverviewJQuery Overview
JQuery Overview
 
Jquery
JqueryJquery
Jquery
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 

More from orestJump

Python - Primi passi
Python - Primi passi Python - Primi passi
Python - Primi passi
orestJump
 
Tecnologie informatiche
Tecnologie informaticheTecnologie informatiche
Tecnologie informatiche
orestJump
 
Php mysql3
Php mysql3Php mysql3
Php mysql3
orestJump
 
Introduzione ai Sistemi Operativi
Introduzione ai Sistemi OperativiIntroduzione ai Sistemi Operativi
Introduzione ai Sistemi Operativi
orestJump
 
Introduzione al livello di rete e Dijkstra algorithm
Introduzione al livello di rete e Dijkstra algorithmIntroduzione al livello di rete e Dijkstra algorithm
Introduzione al livello di rete e Dijkstra algorithm
orestJump
 
Flow chart
Flow chartFlow chart
Flow chart
orestJump
 
Php mysql e cms
Php mysql e cmsPhp mysql e cms
Php mysql e cmsorestJump
 
Html e CSS ipertesti e siti web 4.5
Html e CSS   ipertesti e siti web 4.5Html e CSS   ipertesti e siti web 4.5
Html e CSS ipertesti e siti web 4.5
orestJump
 

More from orestJump (8)

Python - Primi passi
Python - Primi passi Python - Primi passi
Python - Primi passi
 
Tecnologie informatiche
Tecnologie informaticheTecnologie informatiche
Tecnologie informatiche
 
Php mysql3
Php mysql3Php mysql3
Php mysql3
 
Introduzione ai Sistemi Operativi
Introduzione ai Sistemi OperativiIntroduzione ai Sistemi Operativi
Introduzione ai Sistemi Operativi
 
Introduzione al livello di rete e Dijkstra algorithm
Introduzione al livello di rete e Dijkstra algorithmIntroduzione al livello di rete e Dijkstra algorithm
Introduzione al livello di rete e Dijkstra algorithm
 
Flow chart
Flow chartFlow chart
Flow chart
 
Php mysql e cms
Php mysql e cmsPhp mysql e cms
Php mysql e cms
 
Html e CSS ipertesti e siti web 4.5
Html e CSS   ipertesti e siti web 4.5Html e CSS   ipertesti e siti web 4.5
Html e CSS ipertesti e siti web 4.5
 

Recently uploaded

This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
VivekSinghShekhawat2
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 

Recently uploaded (20)

This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptxInternet-Security-Safeguarding-Your-Digital-World (1).pptx
Internet-Security-Safeguarding-Your-Digital-World (1).pptx
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 

Introduzione JQuery

  • 1. jQuery Introduction to using jQuery ugo.rinaldi@gmail.com
  • 2. jQuery • jQuery is a lightweight, "write less, do more", JavaScript library. • The purpose of jQuery is to make it much easier to use JavaScript on your website. • jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code. • jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.
  • 3. Features The jQuery library contains the following features:  HTML/DOM manipulation  CSS manipulation  HTML event methods  Effects and animations  AJAX  Utilities  jQuery will run exactly the same in all major browsers, including Internet Explorer 6!
  • 4. There are several ways to start using jQuery on your web site. You can:  Download the jQuery library from jQuery.com  Include jQuery from a CDN, like Google <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery. min.js"> </script> </head> Adding jQuery
  • 5.  The jQuery syntax is tailor made for selecting HTML elements and performing some action on the element(s).  Basic syntax is: $(selector).action()  A $ sign to define/access jQuery  A (selector) to "query (or find)" HTML elements  A jQuery action() to be performed on the element(s)  Examples:  $(this).hide() - hides the current element.  $("p").hide() - hides all <p> elements.  $(".test").hide() - hides all elements with class="test".  $("#test").hide() - hides the element with id="test". jQuery Syntax
  • 6.  $("*") Selects all elements  $(this) Selects the current HTML element  $("p.intro") Selects all <p> elements with class="intro"  $("p:first") Selects the first <p> element  $("ul li:first") Selects the first <li> element of the first <ul>  $("ul li:first-child") Selects the first <li> element of every <ul>  $("[href]") Selects all elements with an href attribute  $("a[target='_blank']") Selects all <a> elements with a target attribute value equal to "_blank"  $("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank"  $(":button") Selects all <button> elements and <input> elements of type="button"  $("tr:even") Selects all even <tr> elements  $("tr:odd") Selects all odd <tr> elements jQuery selectors like CSS syntax
  • 7.  All the different visitor's actions that a web page can respond to, are called events.  An event represents the precise moment when something happens. Examples:  moving a mouse over an element  selecting a radio button  clicking on an element Events
  • 8. • $(document).ready(function(){ // Insert one of the following event functions }); • $("p").click(function(){ …}); • $("p").dblclick(function(){ …}); • $("p").mouseenter(function(){ //when mouse pointer enters}); • $("p").mouseleave(function(){//when mouse pointer leaves}); • $("p").mousedown(function(){//when click + over}); • $("p").mouseup(function(){//when release + over}); ● $("#p1").hover( function(){ alert("You entered p1!");}, function(){ alert("Bye! You now leave p1!"); } ); Examples
  • 9.  $("p").on({ focus: function(){ $(this).css("background-color", "lightgray"); }, blur: function(){ $(this).css("background-color", "lightblue"); }, click: function(){ $(this).css("background-color", "yellow"); } }); Attach event handlers to elements
  • 10. Effects hide, show, fade  $("#hide").click(function(){ $("p").hide(); // $("p").hide(1000); });  $("p").show();  $("p").toggle();  $(“p”).fadeIn(”slow”,callback function);  $(“p”).fadeOut(”fast”,callback function);  $(“p”).fadeToggle(1500,callback function);  $(“p”).fadeTo(”fast”,0.5,callback function);
  • 11.  With jQuery you can create a sliding effect on elements.  jQuery has the following slide methods:  slideDown()  slideUp()  slideToggle()  Syntax:  $(selector).method(speed,callback); jQuery Sliding Methods
  • 12.  $("button").click(function(){ $("div").animate({ left: '250px‘, opacity: '0.5‘, height: '150px‘, width: ‘+=5px’ }); });  $("button").click(function(){ var div = $("div"); div.animate({height: '300px', opacity: '0.4'}, "slow"); div.animate({width: '300px', opacity: '0.8'}, "slow"); div.animate({height: '100px', opacity: '0.4'}, "slow"); div.animate({width: '100px', opacity: '0.8'}, "slow"); });  $("div").animate({ height: 'toggle’ });  $("#stop").click(function(){ $("#panel").stop(); // interrompe un’animazione }); Animation
  • 13.  A callback function is executed after the current effect is 100% finished. $("button").click(function(){ $("p").hide("slow", function(){ alert("The paragraph is now hidden"); }); });  $("button").click(function(){ $("p").hide(1000); alert("The paragraph is now hidden"); }); Callback function
  • 14.  $("#p1").css("color", "red").slideUp(2000).slideDown(2000);  Si può scrivere anche $("#p1").css("color", "red") .slideUp(2000) .slideDown(2000); Method chaining
  • 15. Simple, but useful, jQuery methods for DOM manipulation/examine are:  text() - Sets or returns the text content of selected elements  html() - Sets or returns the content of selected elements (including HTML markup)  val() - Sets or returns the value of form fields  attr() – Gets attribute value DOM manipulation
  • 16.  // per leggere  $("#btn1").click(function(){ alert("Text: " + $("#test").text()); });  // per scrivere; unico metodo che richiede 2 parametri  $("button").click(function(){ $("#w3s").attr("href", "http://www.w3schools.com/jquery"); });  $("button").click(function(){ $("#w3s").attr({ "href" : "http://www.w3schools.com/jquery", "title" : "W3Schools jQuery Tutorial" }); }); Esempi
  • 17.  $("p").css("background-color");  $("p").css("background-color", "yellow");  $("p").css({"background-color": "yellow", "font- size": "200%"}); css() Method
  • 19.  $("button").click(function(){ var txt = ""; txt += "Width: " + $("#div1").width() + "</br>"; txt += "Height: " + $("#div1").height(); $("#div1").html(txt); });  $("button").click(function(){ var txt = ""; txt += "Document width/height: " + $(document).width(); txt += "x" + $(document).height() + "n"; txt += "Window width/height: " + $(window).width(); txt += "x" + $(window).height(); alert(txt); });  $("button").click(function(){ $("#div1").width(500).height(500); });// per settare insieme widht & height …
  • 20.  AJAX = Asynchronous JavaScript and XML.  In short: AJAX is about loading data in the background and display it on the webpage, without reloading the whole page. Ajax
  • 22. AJAX get() and post() Methods  The jQuery get() and post() methods are used to request data from the server with an HTTP request.  Syntax: $.get(URL,callback(data, status)); $.post(URL,data,callback); Esempi: $("#btn1").click(function(){ $.get("demo_test.asp", function(data, status){ alert("Data: " + data + "nStatus: " + status); }); }); $("button").click(function(){ $.post("demo_test_post.asp", { name: "Donald Duck", city: "Duckburg" }, function(data, status){ alert("Data: " + data + "nStatus: " + status); }); });
  • 23. Esempi e sitografia Qui puoi trovare esempi utili Qui puoi trovare l'intero tutorial ed una Refer ences Guide http://www.w3schools.com