SlideShare uma empresa Scribd logo
1 de 25
Unit 2: jQuery
Lesson 4: Events
October 2, 2013
Lesson 4: Events
Introduction
to jQuery

Syntax and
Structure

Abstraction

Events

Lesson 1

Lesson 2

Lesson 3

Lesson 4

Learning to
Use CSS

Introduction
to CSS

Search
Engine
Optimization

HTML and
Forms

Lesson 8

Lesson 7

Lesson 6

Lesson 5

Separation of
Concerns

3 Ways to
Use CSS

Reusing
Code

Launching
Your Own
Website

Lesson 9

Lesson 10

Lesson 11

Lesson 12

2
Recap from last time (I)
• Abstraction is the process of hiding the complex parts of a system
so that only the important details can be seen
• A gas pedal is an example of an abstraction – it lets us control the
speed of the car without needing to understand what happens under
the hood

3
Recap from last time (II)
• Similarly, jQuery is an abstraction of Javascript – it lets us use
Javascript without having to understand the implementation details

jQuery code
$(document).ready(function() {

$(‘#clickedElement’).click(function() {

$(‘#fadedElement’).fadeOut();
});
});
4
Recap from last time (III)
• Similarly, jQuery is an abstraction of Javascript – it lets us use
Javascript without having to understand the implementation details

jQuery code
$(document).ready(function() {

$(‘#clickedElement’).click(function() {

$(‘#fadedElement’).fadeOut();
});

English translation
Select the document. When it is ready
do the following:
Select the element with id named
clickedElement. If clicked, do the following:
Select the element with id named
fadedElement and make it fade out

});
5
Events are an important part of jQuery
• We saw in Lesson 2 that jQuery often has the same structure
• Today we’ll be focusing on understanding the part of the structure
that relates to events
jQuery code
$(document).ready(function() {

$(pageElement).someEvent(function() {

$(thingToChange).someEffect();

English translation
When the document is ready, do the
following:
When someEvent happens to pageElement,
do the following:

Make someEffect happen to thingToChange

});
});
6
What is a jQuery event?
• An event is any action that a user takes on a web page, such as:
• Double-clicking on a button
• Single-clicking on a button
• Hovering the mouse over an image
• Events are important because they allow us to interact with our
users by responding to their actions

Tom Cruise interacts with a
fancy computer in the 2002
movie Minority Report

7
Events are often used to trigger an effect
• A good example of an event in real-life is stepping on the gas
pedal of a car
• In this case, the driver (the user) initiates the event by pressing
down on the gas pedal

• This event triggers the car to increase its speed

The event (the cause)

The resulting effect
8
jQuery events work in the same way
• jQuery events are similar, except that we get to decide which
events to respond to
Effect

Event
If user

double-clicks on a button,

then

turn the text background color red

If user

single-clicks on a button

then

turn the text background color red

If user

hovers over the image

then

turn the text background color red

9
Time for an example (I)
jQuery code

English translation

$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});

10
Time for an example (II)
jQuery code
$(document).ready(function() {

English translation
When the document is ready, do the
following:

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});

11
Time for an example (III)
jQuery code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

English translation
When the document is ready, do the
following:
When the HTML element with id ‘button’ is
double-clicked, do the following:

$(p).css(“background-color”:
“red”);
});
});

12
Time for an example (IV)
jQuery code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});

English translation
When the document is ready, do the
following:
When the HTML element with id ‘button’ is
double-clicked, do the following
Select the HTML element with <p> tag and
edit its CSS styling for background color to red

13
Time for an example (V)
jQuery code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});
Syntax
notes

$(element)

English translation
When the document is ready, do the
following:
When the HTML element with id ‘button’ is
double-clicked, do the following
Select the HTML element with <p> tag and
edit its CSS styling for background color to red

means “select the element”

14
Time for an example (VI)
jQuery code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});
Syntax
notes

English translation
When the document is ready, do the
following:
When the HTML element with id ‘button’ is
double-clicked, do the following
Select the HTML element with <p> tag and
edit its CSS styling for background color to red

$(element)

means “select the element”

$(element).action()

means “do this action to the element”

15
Time for an example (VII)
jQuery code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});
Syntax
notes

English translation
When the document is ready, do the
following:
When the HTML element with id ‘button’ is
double-clicked, do the following
Select the HTML element with <p> tag and
edit its CSS styling for background color to red

$(element)

means “select the element”

$(element).action()

means “do this action to the element”

function()

means “do the following”
16
Time for an example (VIII)
jQuery code

Before

$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});

Can you figure out how the page
to the right will change?

Need image here (text,
button, and image on page)

After

?
17
Time for an example (IX)
jQuery code

Before

$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});
After double-clicking the button,
the text now has red background

Need image here
(text, button, and image on
page)

After

Need image here (text now
has red background)

18
Time for an example (X)
jQuery code

Before

$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});
After double-clicking the
button, the text now has red
background

Need image here (text,
button, and image on page)

After

Need image here (text now
has red background)

19
Events in action! (I)
• jQuery makes it easy for us to use different events
• If we change our minds and want the text background color to
become red when the user single-clicks on the button, all we need
to do is swap out our one line of jQuery event code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(document).ready(function() {

$(‘#button).click(function() {

$(p).css(“background-color”:
“red”);
});
});

$(p).css(“background-color”:
“red”);
});
});

20
Events in action! (II)
• If we change our minds again and want the text background color
to become red when the user hovers over the image, all we need
to do is swap out our line of jQuery event code

$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(document).ready(function() {

$(‘#img’).hover(function() {

$(p).css(“background-color”:
“red”);
});
});

$(p).css(“background-color”:
“red”);
});
});

21
Summary (I)
• An event is any action that a user takes on a web page, such as:
• Double-clicking on a button
• Single-clicking on a button
• Hovering the mouse over an image
Effect

Event
If user

double-clicks on a button,

then

turn the text background color red

If user

single-clicks on a button

then

turn the text background color red

If user

hovers over the image

then

turn the text background color red
22
Summary (II)
• jQuery makes it easy for us to use different events
• If we change our minds and want to trigger the effect based on a
different event, all we need to do is swap out our line of jQuery
event code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(p).css(“background-color”:
“red”);
});
});

23
Summary (III)
• jQuery makes it easy for us to use different events
• If we change our minds and want to trigger the effect based on a
different event, all we need to do is swap out our line of jQuery
event code
$(document).ready(function() {

$(‘#button’).dblclick(function() {

$(document).ready(function() {

$(‘#button).click(function() {

$(p).css(“background-color”:
“red”);
});
});

$(p).css(“background-color”:
“red”);
});
});

24
What to do on your own
1. Go to URL to complete the Codecademy course online

2. Do the practice set on the material learned

1. Take the follow-up quiz to test your understanding

25

Mais conteúdo relacionado

Destaque

Lesson 109 23 aug13-1430-ay
Lesson 109 23 aug13-1430-ayLesson 109 23 aug13-1430-ay
Lesson 109 23 aug13-1430-ayCodecademy Ren
 
Lesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ayLesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ayCodecademy Ren
 
Lesson 201 14 sep13-1500-ay
Lesson 201 14 sep13-1500-ayLesson 201 14 sep13-1500-ay
Lesson 201 14 sep13-1500-ayCodecademy Ren
 
Lesson 107 23 aug13-1430-ay
Lesson 107 23 aug13-1430-ayLesson 107 23 aug13-1430-ay
Lesson 107 23 aug13-1430-ayCodecademy Ren
 
Lesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ayLesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ayCodecademy Ren
 
Lesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ayLesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ayCodecademy Ren
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayCodecademy Ren
 
Lesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ayLesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ayCodecademy Ren
 
Lesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayLesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayCodecademy Ren
 
Lesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayLesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayCodecademy Ren
 
Lesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayLesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayCodecademy Ren
 
Lesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayCodecademy Ren
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayCodecademy Ren
 

Destaque (13)

Lesson 109 23 aug13-1430-ay
Lesson 109 23 aug13-1430-ayLesson 109 23 aug13-1430-ay
Lesson 109 23 aug13-1430-ay
 
Lesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ayLesson 303 05 jan14-1500-ay
Lesson 303 05 jan14-1500-ay
 
Lesson 201 14 sep13-1500-ay
Lesson 201 14 sep13-1500-ayLesson 201 14 sep13-1500-ay
Lesson 201 14 sep13-1500-ay
 
Lesson 107 23 aug13-1430-ay
Lesson 107 23 aug13-1430-ayLesson 107 23 aug13-1430-ay
Lesson 107 23 aug13-1430-ay
 
Lesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ayLesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ay
 
Lesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ayLesson 205 07 oct13-1500-ay
Lesson 205 07 oct13-1500-ay
 
Lesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ayLesson 203 18 sep13-1500-ay
Lesson 203 18 sep13-1500-ay
 
Lesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ayLesson 101 23 aug13-1430-ay
Lesson 101 23 aug13-1430-ay
 
Lesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ayLesson 102 23 aug13-1430-ay
Lesson 102 23 aug13-1430-ay
 
Lesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ayLesson 105 23 aug13-1430-ay
Lesson 105 23 aug13-1430-ay
 
Lesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ayLesson 304 05 jan14-1500-ay
Lesson 304 05 jan14-1500-ay
 
Lesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ay
 
Lesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ayLesson 202 02 oct13-1800-ay
Lesson 202 02 oct13-1800-ay
 

Semelhante a Lesson 204 03 oct13-1500-ay

JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxAditiPawale1
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material DesignYasin Yildirim
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactOliver N
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQueryorestJump
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentanistar sung
 
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 CombinationSean Burgess
 
JQuery in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in SeasideESUG
 
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 BasicsEPAM Systems
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiMuhammad Ehtisham Siddiqui
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2kshyju
 

Semelhante a Lesson 204 03 oct13-1500-ay (20)

Unit3.pptx
Unit3.pptxUnit3.pptx
Unit3.pptx
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
Getting Started With Material Design
Getting Started With Material DesignGetting Started With Material Design
Getting Started With Material Design
 
Client Web
Client WebClient Web
Client Web
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Om nom nom nom
Om nom nom nomOm nom nom nom
Om nom nom nom
 
The fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose ReactThe fundamental problems of GUI applications and why people choose React
The fundamental problems of GUI applications and why people choose React
 
jQuery
jQueryjQuery
jQuery
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
Jquery
JqueryJquery
Jquery
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
Html5
Html5Html5
Html5
 
J query training
J query trainingJ query training
J query training
 
J query
J queryJ query
J query
 
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 in Seaside
JQuery in SeasideJQuery in Seaside
JQuery in Seaside
 
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
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
 
mobl
moblmobl
mobl
 
Introj Query Pt2
Introj Query Pt2Introj Query Pt2
Introj Query Pt2
 

Mais de Codecademy Ren

Lesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayLesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayCodecademy Ren
 
Lesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayLesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayCodecademy Ren
 
Lesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ayLesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ayCodecademy Ren
 
Lesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayLesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayCodecademy Ren
 
Lesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayLesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayCodecademy Ren
 
Lesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayLesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayCodecademy Ren
 
Lesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayLesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayCodecademy Ren
 
Lesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayLesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayCodecademy Ren
 
Lesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayLesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayCodecademy Ren
 
Lesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayLesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayCodecademy Ren
 

Mais de Codecademy Ren (10)

Lesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ayLesson 301 26 nov13-1500-ay
Lesson 301 26 nov13-1500-ay
 
Lesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ayLesson 207 19 oct13-1500-ay
Lesson 207 19 oct13-1500-ay
 
Lesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ayLesson 206 11 oct13-1500-ay
Lesson 206 11 oct13-1500-ay
 
Lesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ayLesson 112 24 aug13-2300-ay
Lesson 112 24 aug13-2300-ay
 
Lesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ayLesson 108 23 aug13-1430-ay
Lesson 108 23 aug13-1430-ay
 
Lesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ayLesson 106 23 aug13-1430-ay
Lesson 106 23 aug13-1430-ay
 
Lesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ayLesson 102 25 aug13-2200-ay
Lesson 102 25 aug13-2200-ay
 
Lesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ayLesson 103 23 aug13-1430-ay
Lesson 103 23 aug13-1430-ay
 
Lesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ayLesson 104 23 aug13-1430-ay
Lesson 104 23 aug13-1430-ay
 
Lesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ayLesson 111 24 aug13-1430-ay
Lesson 111 24 aug13-1430-ay
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Lesson 204 03 oct13-1500-ay

  • 1. Unit 2: jQuery Lesson 4: Events October 2, 2013
  • 2. Lesson 4: Events Introduction to jQuery Syntax and Structure Abstraction Events Lesson 1 Lesson 2 Lesson 3 Lesson 4 Learning to Use CSS Introduction to CSS Search Engine Optimization HTML and Forms Lesson 8 Lesson 7 Lesson 6 Lesson 5 Separation of Concerns 3 Ways to Use CSS Reusing Code Launching Your Own Website Lesson 9 Lesson 10 Lesson 11 Lesson 12 2
  • 3. Recap from last time (I) • Abstraction is the process of hiding the complex parts of a system so that only the important details can be seen • A gas pedal is an example of an abstraction – it lets us control the speed of the car without needing to understand what happens under the hood 3
  • 4. Recap from last time (II) • Similarly, jQuery is an abstraction of Javascript – it lets us use Javascript without having to understand the implementation details jQuery code $(document).ready(function() { $(‘#clickedElement’).click(function() { $(‘#fadedElement’).fadeOut(); }); }); 4
  • 5. Recap from last time (III) • Similarly, jQuery is an abstraction of Javascript – it lets us use Javascript without having to understand the implementation details jQuery code $(document).ready(function() { $(‘#clickedElement’).click(function() { $(‘#fadedElement’).fadeOut(); }); English translation Select the document. When it is ready do the following: Select the element with id named clickedElement. If clicked, do the following: Select the element with id named fadedElement and make it fade out }); 5
  • 6. Events are an important part of jQuery • We saw in Lesson 2 that jQuery often has the same structure • Today we’ll be focusing on understanding the part of the structure that relates to events jQuery code $(document).ready(function() { $(pageElement).someEvent(function() { $(thingToChange).someEffect(); English translation When the document is ready, do the following: When someEvent happens to pageElement, do the following: Make someEffect happen to thingToChange }); }); 6
  • 7. What is a jQuery event? • An event is any action that a user takes on a web page, such as: • Double-clicking on a button • Single-clicking on a button • Hovering the mouse over an image • Events are important because they allow us to interact with our users by responding to their actions Tom Cruise interacts with a fancy computer in the 2002 movie Minority Report 7
  • 8. Events are often used to trigger an effect • A good example of an event in real-life is stepping on the gas pedal of a car • In this case, the driver (the user) initiates the event by pressing down on the gas pedal • This event triggers the car to increase its speed The event (the cause) The resulting effect 8
  • 9. jQuery events work in the same way • jQuery events are similar, except that we get to decide which events to respond to Effect Event If user double-clicks on a button, then turn the text background color red If user single-clicks on a button then turn the text background color red If user hovers over the image then turn the text background color red 9
  • 10. Time for an example (I) jQuery code English translation $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); 10
  • 11. Time for an example (II) jQuery code $(document).ready(function() { English translation When the document is ready, do the following: $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); 11
  • 12. Time for an example (III) jQuery code $(document).ready(function() { $(‘#button’).dblclick(function() { English translation When the document is ready, do the following: When the HTML element with id ‘button’ is double-clicked, do the following: $(p).css(“background-color”: “red”); }); }); 12
  • 13. Time for an example (IV) jQuery code $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); English translation When the document is ready, do the following: When the HTML element with id ‘button’ is double-clicked, do the following Select the HTML element with <p> tag and edit its CSS styling for background color to red 13
  • 14. Time for an example (V) jQuery code $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); Syntax notes $(element) English translation When the document is ready, do the following: When the HTML element with id ‘button’ is double-clicked, do the following Select the HTML element with <p> tag and edit its CSS styling for background color to red means “select the element” 14
  • 15. Time for an example (VI) jQuery code $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); Syntax notes English translation When the document is ready, do the following: When the HTML element with id ‘button’ is double-clicked, do the following Select the HTML element with <p> tag and edit its CSS styling for background color to red $(element) means “select the element” $(element).action() means “do this action to the element” 15
  • 16. Time for an example (VII) jQuery code $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); Syntax notes English translation When the document is ready, do the following: When the HTML element with id ‘button’ is double-clicked, do the following Select the HTML element with <p> tag and edit its CSS styling for background color to red $(element) means “select the element” $(element).action() means “do this action to the element” function() means “do the following” 16
  • 17. Time for an example (VIII) jQuery code Before $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); Can you figure out how the page to the right will change? Need image here (text, button, and image on page) After ? 17
  • 18. Time for an example (IX) jQuery code Before $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); After double-clicking the button, the text now has red background Need image here (text, button, and image on page) After Need image here (text now has red background) 18
  • 19. Time for an example (X) jQuery code Before $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); After double-clicking the button, the text now has red background Need image here (text, button, and image on page) After Need image here (text now has red background) 19
  • 20. Events in action! (I) • jQuery makes it easy for us to use different events • If we change our minds and want the text background color to become red when the user single-clicks on the button, all we need to do is swap out our one line of jQuery event code $(document).ready(function() { $(‘#button’).dblclick(function() { $(document).ready(function() { $(‘#button).click(function() { $(p).css(“background-color”: “red”); }); }); $(p).css(“background-color”: “red”); }); }); 20
  • 21. Events in action! (II) • If we change our minds again and want the text background color to become red when the user hovers over the image, all we need to do is swap out our line of jQuery event code $(document).ready(function() { $(‘#button’).dblclick(function() { $(document).ready(function() { $(‘#img’).hover(function() { $(p).css(“background-color”: “red”); }); }); $(p).css(“background-color”: “red”); }); }); 21
  • 22. Summary (I) • An event is any action that a user takes on a web page, such as: • Double-clicking on a button • Single-clicking on a button • Hovering the mouse over an image Effect Event If user double-clicks on a button, then turn the text background color red If user single-clicks on a button then turn the text background color red If user hovers over the image then turn the text background color red 22
  • 23. Summary (II) • jQuery makes it easy for us to use different events • If we change our minds and want to trigger the effect based on a different event, all we need to do is swap out our line of jQuery event code $(document).ready(function() { $(‘#button’).dblclick(function() { $(p).css(“background-color”: “red”); }); }); 23
  • 24. Summary (III) • jQuery makes it easy for us to use different events • If we change our minds and want to trigger the effect based on a different event, all we need to do is swap out our line of jQuery event code $(document).ready(function() { $(‘#button’).dblclick(function() { $(document).ready(function() { $(‘#button).click(function() { $(p).css(“background-color”: “red”); }); }); $(p).css(“background-color”: “red”); }); }); 24
  • 25. What to do on your own 1. Go to URL to complete the Codecademy course online 2. Do the practice set on the material learned 1. Take the follow-up quiz to test your understanding 25