SlideShare a Scribd company logo
1 of 32
Beginning jQuery
Review of the Code School course
“Try jQuery” (parts 1–3)
What is jQuery?
• jQuery is JavaScript library
• A “library” in code is the same as the
“modules” you used in Python
– You import the module, which contains a lot of
functions
– Then you can “call” (use) those functions in your
code
• The entire library is written in JavaScript
Lots of resources — http://learn.jquery.com/
How can you include jQuery
in your own Web pages?
Step 1: Include a link to jquery.min.js
in the HEAD of each HTML file.
(Note the Google URL.)
Frequently asked questions
1. Why use the jQuery file hosted at Google?
You don’t need to download jquery.js, and since many websites do it
this way, the file might already be cached by the user’s browser.
2. Why put the SCRIPT tag in the HEAD and not the
BODY?
There is always a debate about this, including an assertion that the
page loads faster if the SCRIPT tag is at the bottom, right before the
closing </body> tag. Others say all SCRIPT tags should be in the
HEAD.
3. Why start the URL with http:// instead of // alone?
You’ll see many pages that leave off the http: in the SCRIPT tag for
Google’s jquery.js. This works on a Web server but not locally, when
the files are on your hard drive.
Step 2: Include a link to your own .js file
in the HEAD of the HTML file.
Place it after the Google jQuery link.
Step 3: Write your own .js file correctly (so it works!).
A well-organized website uses folders.
What you need to get started
1. An HTML document
– With a link to Google’s latest jquery.min.js file
– With a link to your own .js file
2. A JavaScript document or file of your own
– With all the jQuery code between:
$(document).ready(function(){
// and
});
Review of Levels 1–3
http://try.jquery.com/
Download the exercise files!
https://github.com/macloo/
jquery_beginners
[link]
Calling jQuery with $
• Any code statement or instruction that uses
jQuery uses the character “$”
• This will find the text enclosed in H1 tags:
$("h1").text();
• This will change the text enclosed in H1 tags:
$("h1").text("ABC123");
It will change all H1 tags on the page.
Exercises 1 & 2
Find, change an ID or a class
$("#wrapper"); // find the ID wrapper
$(".item"); // find the class item
$("#wrapper").append("<p>Hooray!</p>");
$(".item").append("<p>Hooray!</p>");
Quotation marks may be single or double.
Exercise 3
Searching the DOM
$("#destinations li");
Selects only the LI tags inside the element with the ID
“destinations.” (In the example, the element is a UL.) This would
also include all LI tags inside any nested list that was inside the
“destinations” list.
$("#destinations > li");
Selects only “direct descendants.” The greater-than sign limits
this to only the LIs that are direct children of the ID
“destinations.” No LIs in any nested lists will be affected.
Searching the DOM (2)
$("#destinations li:first");
$("#destinations li:last");
$("#destinations li:odd");
$("#destinations li:even");
These are called “pseudo classes.” They select
just what they say. Can be used to style tables
dynamically, for example.
Exercise 4
“Traversing” the DOM
$("#tours").find("li").last();
$("#tours").find("li").first().next();
$("#tours").find("li").first().parent();
This one goes “up” the DOM to find the direct parent
of the first LI.
$("#tours").children("li");
This finds only the LIs that are the direct children of the list
with the ID “tours.”
Summary of Levels 1 & 2
• We can use jQuery to target an element that
has an ID or a class in the HTML:
"#wrapper", ".photo", etc.
• We can use jQuery to target any element,
using its tag or selector: "h1", "p", "div",
etc.
• We can use jQuery to “walk” up and down the
DOM: next(), first(), parent(), etc.
Level 3: Changing things
.append(x) // at end, inside
.prepend(x) // at top, inside
.before(x) // at top, outside
.after(x) // at end, outside
Example:
$('.vacation').append(price);
Inside the element with the class vacation,
at the bottom, add the value of price.
(Hint: price is a variable!)
Changing things (2)
.appendTo(x) // end, inside
.prependTo(x) // top, inside
.insertBefore(x) // top, outside
.insertAfter(x) // end, outside
Example:
price.appendTo($('.vacation'));
Inside the element with the class vacation, at
the bottom, add the value of price.
open file adding_things.html
Changing things (3)
$('button').remove();
We can use jQuery to completely remove an
element from the HTML page.
In the example at Code School, when we click
the button, the button disappears and is
replaced by a price.
(Note: It will be gone forever.)
A function in jQuery
$('button').on('click', function() {
// some code here
});
This function doesn’t have a name. It calls itself
when someone clicks the button. Whatever
code you write in the middle will run every time
the button (any button) is clicked.
A function in jQuery (2)
$('.choice').on('click', function() {
// some code here
});
This function is exactly the same as the previous
one, but instead of using the name of the HTML
tag (button), here we use a class assigned to
that button (.choice).
Exercise 5
The keyword this
• When you write a function, often you want it
to work for more than one thing.
• Example: You want to build a slideshow with a
thumbnail image for each photo. Click a
thumbnail, and the photo changes.
• How can you use the same function for every
thumbnail and photo in the set?
Exercise 6:
open file photos.html
$('.big').hide();
var current = $('#pics').find('.big').first();
$(current).show().addClass('view');
$('#pics').before(current); // see below
$('.thumb').on('click', function() {
$(current).remove();
current = $(this).prev();
$('#pics').before(current); // see below
$(current).show().addClass('view');
});
// $(z).before(x) - x at top, outside z
Exercise 6
When we move an element
in the DOM, it really moves.
It isn’t in the same place,
even though your source HTML
does not change.
(This is kind of weird.)
The large photo disappears from the DOM
after it is removed.
A little jQuery excitement!
• Tablesorter is a free jQuery plugin that helps
you make beautiful tables:
http://tablesorter.com/docs/#Demo
• That’s a fancy demo. Here’s a simpler demo:
http://macloo.github.io/jquery_beginners/script05.html
The demo comes from JavaScript: Visual
QuickStart Guide (8th ed.), chapter 15 [ link ]
Beginning jQuery
Mindy McAdams
University of Florida
March 2014

More Related Content

What's hot

jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoiddmethvin
 
JS Libraries and jQuery Overview
JS Libraries and jQuery OverviewJS Libraries and jQuery Overview
JS Libraries and jQuery OverviewAleksandr Motsjonov
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterpriseDave Artz
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQueryAngel Ruiz
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgetsvelveeta_512
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 
DTC356 Class Notes: November 19th 2013 (Semantic Markup)
DTC356 Class Notes: November 19th 2013 (Semantic Markup)DTC356 Class Notes: November 19th 2013 (Semantic Markup)
DTC356 Class Notes: November 19th 2013 (Semantic Markup)Nicholas Schiller
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersJonathan Sharp
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
Imaginary users can save your Drupal site
Imaginary users can save your Drupal siteImaginary users can save your Drupal site
Imaginary users can save your Drupal sitejpstacey
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 

What's hot (20)

jQuery Features to Avoid
jQuery Features to AvoidjQuery Features to Avoid
jQuery Features to Avoid
 
JS Libraries and jQuery Overview
JS Libraries and jQuery OverviewJS Libraries and jQuery Overview
JS Libraries and jQuery Overview
 
Jquery
JqueryJquery
Jquery
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
Unobtrusive javascript with jQuery
Unobtrusive javascript with jQueryUnobtrusive javascript with jQuery
Unobtrusive javascript with jQuery
 
Drupal by fire
Drupal by fireDrupal by fire
Drupal by fire
 
jQuery
jQueryjQuery
jQuery
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Getting the Most Out of jQuery Widgets
Getting the Most Out of jQuery WidgetsGetting the Most Out of jQuery Widgets
Getting the Most Out of jQuery Widgets
 
jQuery
jQueryjQuery
jQuery
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Learn css3
Learn css3Learn css3
Learn css3
 
DTC356 Class Notes: November 19th 2013 (Semantic Markup)
DTC356 Class Notes: November 19th 2013 (Semantic Markup)DTC356 Class Notes: November 19th 2013 (Semantic Markup)
DTC356 Class Notes: November 19th 2013 (Semantic Markup)
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Imaginary users can save your Drupal site
Imaginary users can save your Drupal siteImaginary users can save your Drupal site
Imaginary users can save your Drupal site
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 

Similar to Beginning jQuery

Similar to Beginning jQuery (20)

Jquery tutorial-beginners
Jquery tutorial-beginnersJquery tutorial-beginners
Jquery tutorial-beginners
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 
jQuery - Web Engineering
jQuery - Web Engineering jQuery - Web Engineering
jQuery - Web Engineering
 
J query
J queryJ query
J query
 
Introduction to jquery mobile with Phonegap
Introduction to jquery mobile with PhonegapIntroduction to jquery mobile with Phonegap
Introduction to jquery mobile with Phonegap
 
Jquery
JqueryJquery
Jquery
 
jQuery
jQueryjQuery
jQuery
 
Jquery library
Jquery libraryJquery library
Jquery library
 
Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
 
Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap Advanced JQuery Mobile tutorial with Phonegap
Advanced JQuery Mobile tutorial with Phonegap
 
J query intro_29thsep_alok
J query intro_29thsep_alokJ query intro_29thsep_alok
J query intro_29thsep_alok
 
Jquery
JqueryJquery
Jquery
 
Instagram filters
Instagram filters Instagram filters
Instagram filters
 
jQuery
jQueryjQuery
jQuery
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 

More from Mindy McAdams

Multimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the ClassroomMultimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the ClassroomMindy McAdams
 
Summary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshopSummary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshopMindy McAdams
 
U.S. j-schools and digital skills
U.S. j-schools and digital skills U.S. j-schools and digital skills
U.S. j-schools and digital skills Mindy McAdams
 
New skill sets for journalism
New skill sets for journalismNew skill sets for journalism
New skill sets for journalismMindy McAdams
 
Journalism blogs: An introduction
Journalism blogs: An introduction Journalism blogs: An introduction
Journalism blogs: An introduction Mindy McAdams
 
Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13Mindy McAdams
 
Journalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not NewspapersJournalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not NewspapersMindy McAdams
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 CanvasMindy McAdams
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOMMindy McAdams
 
HTML and Responsive Design
HTML and Responsive Design HTML and Responsive Design
HTML and Responsive Design Mindy McAdams
 
Design Concepts and Web Design
Design Concepts and Web DesignDesign Concepts and Web Design
Design Concepts and Web DesignMindy McAdams
 
Learning Python - Week 4
Learning Python - Week 4 Learning Python - Week 4
Learning Python - Week 4 Mindy McAdams
 
Learning Python - Week 2
Learning Python - Week 2Learning Python - Week 2
Learning Python - Week 2Mindy McAdams
 
Learning Python - Week 1
Learning Python - Week 1Learning Python - Week 1
Learning Python - Week 1Mindy McAdams
 
Freedom of Speech - Louis Brandeis
Freedom of Speech - Louis BrandeisFreedom of Speech - Louis Brandeis
Freedom of Speech - Louis BrandeisMindy McAdams
 
Networked Information Economy / Benkler
Networked Information Economy / BenklerNetworked Information Economy / Benkler
Networked Information Economy / BenklerMindy McAdams
 

More from Mindy McAdams (20)

Just Enough Code
Just Enough CodeJust Enough Code
Just Enough Code
 
Multimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the ClassroomMultimedia Journalism Innovations in the Classroom
Multimedia Journalism Innovations in the Classroom
 
Summary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshopSummary of journalism faculty curriculum workshop
Summary of journalism faculty curriculum workshop
 
Crowdsourcing
CrowdsourcingCrowdsourcing
Crowdsourcing
 
U.S. j-schools and digital skills
U.S. j-schools and digital skills U.S. j-schools and digital skills
U.S. j-schools and digital skills
 
New skill sets for journalism
New skill sets for journalismNew skill sets for journalism
New skill sets for journalism
 
Journalism blogs: An introduction
Journalism blogs: An introduction Journalism blogs: An introduction
Journalism blogs: An introduction
 
Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13Why Your Newsroom Should Be Using WordPress - ONA13
Why Your Newsroom Should Be Using WordPress - ONA13
 
Journalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not NewspapersJournalism's Future: Journalism, Not Newspapers
Journalism's Future: Journalism, Not Newspapers
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
JavaScript 101
JavaScript 101JavaScript 101
JavaScript 101
 
HTML and Responsive Design
HTML and Responsive Design HTML and Responsive Design
HTML and Responsive Design
 
Design Concepts and Web Design
Design Concepts and Web DesignDesign Concepts and Web Design
Design Concepts and Web Design
 
Learning Python - Week 4
Learning Python - Week 4 Learning Python - Week 4
Learning Python - Week 4
 
Learning Python - Week 2
Learning Python - Week 2Learning Python - Week 2
Learning Python - Week 2
 
Learning Python - Week 1
Learning Python - Week 1Learning Python - Week 1
Learning Python - Week 1
 
Learning Python
Learning PythonLearning Python
Learning Python
 
Freedom of Speech - Louis Brandeis
Freedom of Speech - Louis BrandeisFreedom of Speech - Louis Brandeis
Freedom of Speech - Louis Brandeis
 
Networked Information Economy / Benkler
Networked Information Economy / BenklerNetworked Information Economy / Benkler
Networked Information Economy / Benkler
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Beginning jQuery

  • 1. Beginning jQuery Review of the Code School course “Try jQuery” (parts 1–3)
  • 2.
  • 3. What is jQuery? • jQuery is JavaScript library • A “library” in code is the same as the “modules” you used in Python – You import the module, which contains a lot of functions – Then you can “call” (use) those functions in your code • The entire library is written in JavaScript
  • 4. Lots of resources — http://learn.jquery.com/
  • 5. How can you include jQuery in your own Web pages?
  • 6. Step 1: Include a link to jquery.min.js in the HEAD of each HTML file. (Note the Google URL.)
  • 7. Frequently asked questions 1. Why use the jQuery file hosted at Google? You don’t need to download jquery.js, and since many websites do it this way, the file might already be cached by the user’s browser. 2. Why put the SCRIPT tag in the HEAD and not the BODY? There is always a debate about this, including an assertion that the page loads faster if the SCRIPT tag is at the bottom, right before the closing </body> tag. Others say all SCRIPT tags should be in the HEAD. 3. Why start the URL with http:// instead of // alone? You’ll see many pages that leave off the http: in the SCRIPT tag for Google’s jquery.js. This works on a Web server but not locally, when the files are on your hard drive.
  • 8. Step 2: Include a link to your own .js file in the HEAD of the HTML file. Place it after the Google jQuery link.
  • 9. Step 3: Write your own .js file correctly (so it works!).
  • 10. A well-organized website uses folders.
  • 11. What you need to get started 1. An HTML document – With a link to Google’s latest jquery.min.js file – With a link to your own .js file 2. A JavaScript document or file of your own – With all the jQuery code between: $(document).ready(function(){ // and });
  • 12. Review of Levels 1–3 http://try.jquery.com/
  • 13. Download the exercise files! https://github.com/macloo/ jquery_beginners [link]
  • 14. Calling jQuery with $ • Any code statement or instruction that uses jQuery uses the character “$” • This will find the text enclosed in H1 tags: $("h1").text(); • This will change the text enclosed in H1 tags: $("h1").text("ABC123"); It will change all H1 tags on the page. Exercises 1 & 2
  • 15. Find, change an ID or a class $("#wrapper"); // find the ID wrapper $(".item"); // find the class item $("#wrapper").append("<p>Hooray!</p>"); $(".item").append("<p>Hooray!</p>"); Quotation marks may be single or double. Exercise 3
  • 16. Searching the DOM $("#destinations li"); Selects only the LI tags inside the element with the ID “destinations.” (In the example, the element is a UL.) This would also include all LI tags inside any nested list that was inside the “destinations” list. $("#destinations > li"); Selects only “direct descendants.” The greater-than sign limits this to only the LIs that are direct children of the ID “destinations.” No LIs in any nested lists will be affected.
  • 17. Searching the DOM (2) $("#destinations li:first"); $("#destinations li:last"); $("#destinations li:odd"); $("#destinations li:even"); These are called “pseudo classes.” They select just what they say. Can be used to style tables dynamically, for example. Exercise 4
  • 18. “Traversing” the DOM $("#tours").find("li").last(); $("#tours").find("li").first().next(); $("#tours").find("li").first().parent(); This one goes “up” the DOM to find the direct parent of the first LI. $("#tours").children("li"); This finds only the LIs that are the direct children of the list with the ID “tours.”
  • 19. Summary of Levels 1 & 2 • We can use jQuery to target an element that has an ID or a class in the HTML: "#wrapper", ".photo", etc. • We can use jQuery to target any element, using its tag or selector: "h1", "p", "div", etc. • We can use jQuery to “walk” up and down the DOM: next(), first(), parent(), etc.
  • 20. Level 3: Changing things .append(x) // at end, inside .prepend(x) // at top, inside .before(x) // at top, outside .after(x) // at end, outside Example: $('.vacation').append(price); Inside the element with the class vacation, at the bottom, add the value of price. (Hint: price is a variable!)
  • 21. Changing things (2) .appendTo(x) // end, inside .prependTo(x) // top, inside .insertBefore(x) // top, outside .insertAfter(x) // end, outside Example: price.appendTo($('.vacation')); Inside the element with the class vacation, at the bottom, add the value of price. open file adding_things.html
  • 22.
  • 23. Changing things (3) $('button').remove(); We can use jQuery to completely remove an element from the HTML page. In the example at Code School, when we click the button, the button disappears and is replaced by a price. (Note: It will be gone forever.)
  • 24. A function in jQuery $('button').on('click', function() { // some code here }); This function doesn’t have a name. It calls itself when someone clicks the button. Whatever code you write in the middle will run every time the button (any button) is clicked.
  • 25. A function in jQuery (2) $('.choice').on('click', function() { // some code here }); This function is exactly the same as the previous one, but instead of using the name of the HTML tag (button), here we use a class assigned to that button (.choice). Exercise 5
  • 26. The keyword this • When you write a function, often you want it to work for more than one thing. • Example: You want to build a slideshow with a thumbnail image for each photo. Click a thumbnail, and the photo changes. • How can you use the same function for every thumbnail and photo in the set? Exercise 6: open file photos.html
  • 27. $('.big').hide(); var current = $('#pics').find('.big').first(); $(current).show().addClass('view'); $('#pics').before(current); // see below $('.thumb').on('click', function() { $(current).remove(); current = $(this).prev(); $('#pics').before(current); // see below $(current).show().addClass('view'); }); // $(z).before(x) - x at top, outside z Exercise 6
  • 28. When we move an element in the DOM, it really moves. It isn’t in the same place, even though your source HTML does not change. (This is kind of weird.) The large photo disappears from the DOM after it is removed.
  • 29. A little jQuery excitement! • Tablesorter is a free jQuery plugin that helps you make beautiful tables: http://tablesorter.com/docs/#Demo • That’s a fancy demo. Here’s a simpler demo: http://macloo.github.io/jquery_beginners/script05.html The demo comes from JavaScript: Visual QuickStart Guide (8th ed.), chapter 15 [ link ]
  • 30.
  • 31.

Editor's Notes

  1. CONTACT ----- http://mindymcadams.com/ ----- Lecture by Mindy McAdams, University of Florida. UpdatedMarch 2014. COURSE http://try.jquery.com/
  2. SOURCE http://jquery.com/
  3. SOURCE http://learn.jquery.com/
  4. SOURCE https://developers.google.com/speed/libraries/
  5. (1) http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/ (2) http://stackoverflow.com/questions/1013112/where-should-i-declare-javascript-files-used-in-my-page-in-head-head-or-nea (3) http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/ And -- http://stackoverflow.com/questions/2180391/why-should-i-use-googles-cdn-for-jqueryAnd -- http://www.impressivewebs.com/linking-to-jquery/
  6. Note the use of a separate folder (directory) to store all JS files. Usually it will be named /scripts/ or /script/. Like an /images/ folder and a /css/ folder, this is standard professional practice for organizing a website’s files and folders in a logical, maintainable way. THE FILE EXTENSION MUST BE .js
  7. The stuff above and below the dashed lines is essential, necessary, required. The part that is highlight in YELLOW. All the jQuery must appear BETWEEN those two lines.
  8. SOURCE http://try.jquery.com/
  9. LINK https://github.com/macloo/jquery_beginners
  10. Exercises 1 and 2 in the JS file
  11. Exercise 3 in the JS file
  12. Exercise 4 in the JS file
  13. Append: Within a DIV (or any node) with the class “vacation,” price will be inserted at the end, inside that DIV. Prepend is also inside, but at the top. Before is immediately before the DIV, outside it. After is also outside.
  14. appendTo: Within a DIV (or any node) with the class “vacation,” price will be inserted at the end, inside that DIV. prependTois also inside, but at the top. insertBefore is immediately before the DIV, outside it. insertAfter is also outside.
  15. SEE live version - http://macloo.github.io/jquery_beginners/adding_things.html
  16. Exercise 5 in the JS file
  17. Exercise 6 in the JS file
  18. An example of the keyword this.
  19. Making HTML tables more usable and dynamic is a very common use of jQuery. DOWNLOAD tablesorter.js from http://tablesorter.com/docs/
  20. Linked files were copied from &quot;JavaScript: Visual QuickStart Guide, 8th Edition,&quot; chapter 15, for demonstration purposes. http://www.peachpit.com/store/javascript-visual-quickstart-guide-9780321772978 http://www.javascriptworld.com/
  21. A good jQuery book: http://www.sitepoint.com/store/jquery-novice-to-ninja-new-kicks-and-tricks/
  22. CONTACT ----- http://mindymcadams.com/ ----- Lecture by Mindy McAdams, University of Florida. Updated March 2014.