SlideShare a Scribd company logo
jQuery
CS 329E - Fall 2013
Source
www.w3schools.com/jquery
Click on “Next Chapter” to begin.
Download and Use Script
jQuery.com/download:
Choose compressed or uncompressed.
Right-click page, “Save As”.
Add to HTML (to head):
<script src = “jquery-1.10.2.min.js” > </script>
Or just use Google’s copy:
<script src = “http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js” >
</script>
Add the script before your other .js files.
Syntax
$(selector).action()
Examples:
$(document).ready( function() { … } );
$(this).hide();
$(“h1”).show();
$(“#someElement”).fadeIn( “slow” );
$(“.someClass”).fadeOut( “fast” );
Selectors
Similar to CSS
$(“*”)
$(“p.someClass”)
$(“[href]”)
$(“tr:even”)
Select by ID (#) and class (.), etc.
*By name (attribute): $(‘[name=“someName”]’)
List of Nice Examples:
www.w3schools.com/jquery/jquery_selectors.asp
$(document).ready()
Sometimes you need to wait for everything to load.
● When you need your code to run right away.
● For example, if you need to do this right after you load the page:
$(“#myDiv”).hide();
● No need if the user triggers an event (e.g. pressing a button).
$(document).ready( function() {
// code goes here
});
Manipulating CSS
$(“#myElement”).css(“color”, “red”);
$(“.myClass”).css(“margin”, “30px”);
$(“body”).css(“background-color”,
“#FFFF00”);
jQuery Events
Common Mouse Events:
click, dblclick, mouseenter, mouseleave, hover
Common Keyboard Events:
keypress, keydown, keyup
Common Form Events:
submit, change, focus, blur
Common Document Events:
load, resize, scroll, unload
www.w3schools.com/jquery/jquery_events.asp
Event Examples
$(“#myElement”).click( function() {
alert(“You clicked me!”);
});
$(“p”).dblclick( function() {
$(this).hide();
});
$(“.colorful”).hover( function() {
$(this).css(“background-color: FF0000”); // mouse enter
}, function () {
$(this).css(“background-color: 0000FF”); // mouse exit
}
Useful jQuery Effects
$(selector).function(speed, callback) - params are optional
callback: function that is called when finished
hide(), show(), toggle()
$(“#myDiv”).hide(500, function() { alert(“I am hidden.”) });
fadeIn(), fadeOut(), fadeToggle(), fadeTo()
$(“#myDiv”).fadeTo(“slow”, 0.5); // *second param is opacity
slideUp(), slideDown(), slideToggle()
animate({params}, speed, callback) - goes to given params over time
stop - stop animation before it’s finished
jQuery Chaining
jQuery Usually Returns the Object.
Avoid making the browser find the same element over and over.
Example:
$(“#myElement”).css(“color”, “red”)
.slideUp(2000)
.slideDown(2000);
Content and Attributes
Getting and Setting Content from DOM:
text(), html(), val(), attr()
Example:
alert(“Your input is: “ + $(“#myDiv”).text()); alert
(“The HTML is: “ + $(“#myDiv”).html());
$(“#myDiv”).text(“Hello, World!”); // set text
$(“#myDiv”).html(“<b>Hello, World!</b>”); // set html
Attribute Example:
alert(“The URL is: “ + $(“#myLink”).attr(“href”));
Other Useful Methods
append(), prepend(), after(), before()
www.w3schools.com/jquery/jquery_dom_add.asp
remove(), empty()
www.w3schools.com/jquery/jquery_dom_remove.asp
addClass(), removeClass(), toggleClass(), css()
http://www.w3schools.com/jquery/jquery_css_classes.asp
width(), height(), etc.
http://www.w3schools.com/jquery/jquery_dimensions.asp
Traversing Element Trees
parent(), parents(), children(), find()
http://www.w3schools.com/jquery/jquery_traversing_descendants.asp
$(“#myDiv”).find(“span”); // returns all span descendants
$(“#myDiv”).find(“*”); // returns all descendants
siblings(), next(), nextAll(), nextUntil(),
prev(), prevAll(), prevUntil()
http://www.w3schools.com/jquery/jquery_traversing_siblings.asp
first(), last(), eq(), filter(), not()
http://www.w3schools.com/jquery/jquery_traversing_filtering.asp
Ajax
“Asynchronous Javascript and XML”
Get data without reloading your page.
http://www.w3schools.com/jquery/jquery_ajax_intro.asp
$(selector).load(URL, data, callback)
var myURL = “someFile.txt”; // or “http://www.mysite.com/myFile.txt”
$(“#myButton”).click( function() {
// Pass in the URL and a callback function.
// xhr is the XMLHttpRequest object.
$(“#myDiv”).load(myURL, function(response, status, xhr) {
if(status == “success”)
alert(response);
else if(status == “error”)
alert(“Error: “ + xhr.statusText);
});
});
Ajax: GET and POST
You know all about GET and POST.
$.get(URL, callback);
$.post(URL, data, callback);
var myURL = “someScript.php”; // or some server-side script
$.post(
myURL, // URL of script
{ // data to submit in the form of an object
name: “John Smith”,
age: 433
},
function(data, status) { ... } // callback function
);
Useful Links
jQuery Tricks:
http://net.tutsplus.com/tutorials/javascript-ajax/14-helpful-jquery-tricks-notes-and-best-practices/
Some jQuery Plugins
http://tutorialzine.com/2013/04/50-amazing-jquery-plugins/
jQuery UI:
http://jqueryui.com/
jQuery Documentation
api.jquery.com

More Related Content

What's hot

Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
Jack Franklin
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
Rod Johnson
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
Sudar Muthu
 
jQuery
jQueryjQuery
jQuery
Jay Poojara
 
jQuery
jQueryjQuery
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
Remy Sharp
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Ayes Chinmay
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
Gil Fink
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
Remy Sharp
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Treeadamlogic
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
Eyal Vardi
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
Remy Sharp
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
Karol Depka Pradzinski
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
manugoel2003
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and ModernizrJussi Pohjolainen
 

What's hot (20)

Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery
jQueryjQuery
jQuery
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Jquery
JqueryJquery
Jquery
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Tree
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
D3.js and SVG
D3.js and SVGD3.js and SVG
D3.js and SVG
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
JQuery
JQueryJQuery
JQuery
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 

Similar to Jquery presentation

jQuery
jQueryjQuery
Jquery
JqueryJquery
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
Thinqloud
 
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
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
Rob Bontekoe
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
bensmithett
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Nagaraju Sangam
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
azz71
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
Isfand yar Khan
 
Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用
LearningTech
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
Simon Willison
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
Hyeonseok Shin
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
Shumpei Shiraishi
 
Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tips
anubavam-techkt
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
Stijn Van Minnebruggen
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Knowgirish82
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
iFour Institute - Sustainable Learning
 
jQuery
jQueryjQuery

Similar to Jquery presentation (20)

jQuery
jQueryjQuery
jQuery
 
Jquery
JqueryJquery
Jquery
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
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
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Styling components with JavaScript
Styling components with JavaScriptStyling components with JavaScript
Styling components with JavaScript
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
presentation_jquery_ppt.pptx
presentation_jquery_ppt.pptxpresentation_jquery_ppt.pptx
presentation_jquery_ppt.pptx
 
Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
 
Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用Html, CSS, Javascript, Jquery, Meteor應用
Html, CSS, Javascript, Jquery, Meteor應用
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
jQuery Basic API
jQuery Basic APIjQuery Basic API
jQuery Basic API
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
Jquery optimization-tips
Jquery optimization-tipsJquery optimization-tips
Jquery optimization-tips
 
jQuery basics
jQuery basicsjQuery basics
jQuery basics
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 
jQuery
jQueryjQuery
jQuery
 

Recently uploaded

Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
AG2 Design
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Delivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and TrainingDelivering Micro-Credentials in Technical and Vocational Education and Training
Delivering Micro-Credentials in Technical and Vocational Education and Training
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Jquery presentation

  • 1. jQuery CS 329E - Fall 2013
  • 3. Download and Use Script jQuery.com/download: Choose compressed or uncompressed. Right-click page, “Save As”. Add to HTML (to head): <script src = “jquery-1.10.2.min.js” > </script> Or just use Google’s copy: <script src = “http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js” > </script> Add the script before your other .js files.
  • 4. Syntax $(selector).action() Examples: $(document).ready( function() { … } ); $(this).hide(); $(“h1”).show(); $(“#someElement”).fadeIn( “slow” ); $(“.someClass”).fadeOut( “fast” );
  • 5. Selectors Similar to CSS $(“*”) $(“p.someClass”) $(“[href]”) $(“tr:even”) Select by ID (#) and class (.), etc. *By name (attribute): $(‘[name=“someName”]’) List of Nice Examples: www.w3schools.com/jquery/jquery_selectors.asp
  • 6. $(document).ready() Sometimes you need to wait for everything to load. ● When you need your code to run right away. ● For example, if you need to do this right after you load the page: $(“#myDiv”).hide(); ● No need if the user triggers an event (e.g. pressing a button). $(document).ready( function() { // code goes here });
  • 7. Manipulating CSS $(“#myElement”).css(“color”, “red”); $(“.myClass”).css(“margin”, “30px”); $(“body”).css(“background-color”, “#FFFF00”);
  • 8. jQuery Events Common Mouse Events: click, dblclick, mouseenter, mouseleave, hover Common Keyboard Events: keypress, keydown, keyup Common Form Events: submit, change, focus, blur Common Document Events: load, resize, scroll, unload www.w3schools.com/jquery/jquery_events.asp
  • 9. Event Examples $(“#myElement”).click( function() { alert(“You clicked me!”); }); $(“p”).dblclick( function() { $(this).hide(); }); $(“.colorful”).hover( function() { $(this).css(“background-color: FF0000”); // mouse enter }, function () { $(this).css(“background-color: 0000FF”); // mouse exit }
  • 10. Useful jQuery Effects $(selector).function(speed, callback) - params are optional callback: function that is called when finished hide(), show(), toggle() $(“#myDiv”).hide(500, function() { alert(“I am hidden.”) }); fadeIn(), fadeOut(), fadeToggle(), fadeTo() $(“#myDiv”).fadeTo(“slow”, 0.5); // *second param is opacity slideUp(), slideDown(), slideToggle() animate({params}, speed, callback) - goes to given params over time stop - stop animation before it’s finished
  • 11. jQuery Chaining jQuery Usually Returns the Object. Avoid making the browser find the same element over and over. Example: $(“#myElement”).css(“color”, “red”) .slideUp(2000) .slideDown(2000);
  • 12. Content and Attributes Getting and Setting Content from DOM: text(), html(), val(), attr() Example: alert(“Your input is: “ + $(“#myDiv”).text()); alert (“The HTML is: “ + $(“#myDiv”).html()); $(“#myDiv”).text(“Hello, World!”); // set text $(“#myDiv”).html(“<b>Hello, World!</b>”); // set html Attribute Example: alert(“The URL is: “ + $(“#myLink”).attr(“href”));
  • 13. Other Useful Methods append(), prepend(), after(), before() www.w3schools.com/jquery/jquery_dom_add.asp remove(), empty() www.w3schools.com/jquery/jquery_dom_remove.asp addClass(), removeClass(), toggleClass(), css() http://www.w3schools.com/jquery/jquery_css_classes.asp width(), height(), etc. http://www.w3schools.com/jquery/jquery_dimensions.asp
  • 14. Traversing Element Trees parent(), parents(), children(), find() http://www.w3schools.com/jquery/jquery_traversing_descendants.asp $(“#myDiv”).find(“span”); // returns all span descendants $(“#myDiv”).find(“*”); // returns all descendants siblings(), next(), nextAll(), nextUntil(), prev(), prevAll(), prevUntil() http://www.w3schools.com/jquery/jquery_traversing_siblings.asp first(), last(), eq(), filter(), not() http://www.w3schools.com/jquery/jquery_traversing_filtering.asp
  • 15. Ajax “Asynchronous Javascript and XML” Get data without reloading your page. http://www.w3schools.com/jquery/jquery_ajax_intro.asp $(selector).load(URL, data, callback) var myURL = “someFile.txt”; // or “http://www.mysite.com/myFile.txt” $(“#myButton”).click( function() { // Pass in the URL and a callback function. // xhr is the XMLHttpRequest object. $(“#myDiv”).load(myURL, function(response, status, xhr) { if(status == “success”) alert(response); else if(status == “error”) alert(“Error: “ + xhr.statusText); }); });
  • 16. Ajax: GET and POST You know all about GET and POST. $.get(URL, callback); $.post(URL, data, callback); var myURL = “someScript.php”; // or some server-side script $.post( myURL, // URL of script { // data to submit in the form of an object name: “John Smith”, age: 433 }, function(data, status) { ... } // callback function );
  • 17. Useful Links jQuery Tricks: http://net.tutsplus.com/tutorials/javascript-ajax/14-helpful-jquery-tricks-notes-and-best-practices/ Some jQuery Plugins http://tutorialzine.com/2013/04/50-amazing-jquery-plugins/ jQuery UI: http://jqueryui.com/