SlideShare a Scribd company logo
1 of 30
Unit 2: jQuery
Lesson 2: Syntax and Structure
October 2, 2013
Lesson 2: jQuery and Javascript
Introduction
to jQuery

Syntax and
Structure

Abstraction

Pictures, Vid
eo, and
Media

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)
• jQuery is one of the fastest ways to bring movement to a webpage
and have it come to life
• It’s easy to use because it’s not a programming language of its own;
instead it is a library (a bunch of commonly used pieces of code),
written in a programming language called Javascript
• To use jQuery, you don’t need to know Javascript (we will cover this
in detail in Unit 3)

3
Recap from last time (II)
• Just as a French phrase book helps us understand common
phrases without knowing individual words, jQuery helps us with
common features without needing to understand Javascript
• jQuery takes the Javascript code needed to run each of these
common features and packages them into some simple commands

4
Three benefits of jQuery over Javascript
1. Fewer mistakes – jQuery’s simple structure makes it easier to
1
identify mistakes. Fewer mistakes means less time spent
debugging!

2
2. Less code – jQuery often requires only a few lines of code in
comparison to Javascript

3
1. Faster to learn – the intuitive structure makes for a more gradual
learning curve. It’s one of the easiest ways to add movement to a
webpage!

5
1

jQuery uses a consistent structure
• jQuery code is usually structured the same way – that’s what
makes it easy to learn!
• So whether you want to zoom in on an image or make some text
disappear, the structure of your code will probably be the same

• It may look confusing at first, but you’ll quickly get the hang of it
after you have seen it a few times

6
1

jQuery structure and syntax (I)
jQuery code

English translation

$(document).ready(function() {

$(pageElement).someEvent(function() {

$(thingToChange).someEffect();
});
});

7
1

jQuery structure and syntax (II)
jQuery code
$(document).ready(function() {

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

$(pageElement).someEvent(function() {

$(thingToChange).someEffect();
});
});

8
1

jQuery structure and syntax (III)
jQuery code
$(document).ready(function() {

$(pageElement).someEvent(function() {

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

$(thingToChange).someEffect();
});
});

9
1

jQuery structure and syntax (IV)
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

});
});

10
1

jQuery structure and syntax (V)
jQuery code

English translation

$(document).ready(function() {

When the document is ready, do the
following:

$(pageElement).someEvent(function() {

$(thingToChange).someEffect();

When someEvent happens to pageElement,
do the following:
Make someEffect happen to thingToChange

});
});
Syntax
notes

$(element)

means “select the element”

11
1

jQuery structure and syntax (VI)
jQuery code

English translation

$(document).ready(function() {

When the document is ready, do the
following:

$(pageElement).someEvent(function() {

$(thingToChange).someEffect();

When someEvent happens to pageElement,
do the following:
Make someEffect happen to thingToChange

});
});
Syntax
notes

$(element)

means “select the element”

$(element).action()

means “do this action to the element”

12
1

jQuery structure and syntax (VII)
jQuery code

English translation

$(document).ready(function() {

When the document is ready, do the
following:

$(pageElement).someEvent(function() {

$(thingToChange).someEffect();

When someEvent happens to
pageElement, do the following:
Make someEffect happen to thingToChange

});
});
Syntax
notes

$(element)

means “select the element”

$(element).action()

means “do this action to the element”

function()

means “do the following”
13
2

jQuery is a simpler version of Javascript (I)
• Let’s look at a live example. Say we want to have an alert pop up when
the user clicks

Original page

After clicking the text,
a popup appears

14
2

jQuery is a simpler version of Javascript (II)
• We can enable this behavior by using either jQuery or Javascript

• The effect of the two code snippets below is identical!
Javascript
var anchors =document.getElementsByTagName(“a”);
for(var z =0; z < anchors.length; z++){
var elem = anchors[z];
elem.onclick = function(){
alert(“hello”);
};
}

jQuery
$(document).ready(function() {
$('a').click(function() {
alert('hello');
});
});

15
2

jQuery is a simpler version of Javascript (III)
• As you can see, parts of the code are the same, but the jQuery version
removes a lot of the complexity that you get with Javascript

Javascript

jQuery

var anchors =document.getElementsByTagName(“a”);
for(var z =0; z < anchors.length; z++){
var elem = anchors[z];
elem.onclick = function(){
alert(“hello”);
};
}

$(document).ready(function() {
$('a').click(function() {
alert('hello');
});
});

The code triggering the alert is identical
16
3

Translating jQuery into English (I)
jQuery code

English translation

$(document).ready(function() {

$('a').click(function() {

alert('hello');
});
});
Syntax
notes

17
3

Translating jQuery into English (II)
jQuery code
$(document).ready(function() {

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

$('a').click(function() {

alert('hello');
});
});
Syntax
notes

18
3

Translating jQuery into English (III)
jQuery code
$(document).ready(function() {

$('a').click(function() {

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:

alert('hello');
});
});
Syntax
notes

19
3

Translating jQuery into English (IV)
jQuery code
$(document).ready(function() {

$('a').click(function() {

alert('hello');

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

});
});
Syntax
notes

20
3

Translating jQuery into English (V)
jQuery code
$(document).ready(function() {

$('a').click(function() {

alert('hello');

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

});
});
Syntax
notes

$(element)

means “select the element”

21
3

Translating jQuery into English (VI)
jQuery code
$(document).ready(function() {

$('a').click(function() {

alert('hello');

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

});
});
Syntax
notes

$(element)

means “select the element”

$(element).action()

means “do this action to the element”

22
3

Translating jQuery into English (VII)
jQuery code
$(document).ready(function() {

$('a').click(function() {

alert('hello');

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

});
});
Syntax
notes

$(element)

means “select the element”

$(element).action()

means “do this action to the element”

function()

means “do the following”
23
3

Translating jQuery into English (VII)
jQuery code
$(document).ready(function() {
$('a').click(function() {
alert('hello');
});
});

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

24
3

Translating jQuery into English (VII)
jQuery code
$(document).ready(function() {
$('a').click(function() {
alert('hello');
});
});

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

Original page

Result after clicking

25
Summary (I)
• jQuery has three main benefits over Javascript:
1) Fewer mistakes
2) Less code
3) Faster to learn
• jQuery code has a consistent structure
jQuery code

$(document).ready(function() {

$(pageElement).someEvent(function() {

$(thingToChange).someEffect();
});
});
26
Summary (II)
• jQuery has three main benefits over Javascript:
1) Fewer mistakes
2) Less code
3) Faster to learn
• jQuery code has a consistent structure
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

});
});
27
Summary (III)
jQuery code
$(document).ready(function() {
$('a').click(function() {
alert('hello');
});
});

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

28
Summary (IV)
jQuery code
$(document).ready(function() {
$('a').click(function() {
alert('hello');
});
});

English translation
When the document is ready, do the
following:
When the HTML element with an <a> tag
is clicked, do the following:
Send an alert that says “hello”

Original page

Result after clicking

29
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

30

More Related Content

What's hot

SharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuerySharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQueryMark Rackley
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery維佋 唐
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaEdureka!
 
Android training day 4
Android training day 4Android training day 4
Android training day 4Vivek Bhusal
 
Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Iakiv Kramarenko
 
Android training day 5
Android training day 5Android training day 5
Android training day 5Vivek Bhusal
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Eventsdmethvin
 
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..Mark Rackley
 
Building Smart Workflows - Dan Diebolt
Building Smart Workflows - Dan DieboltBuilding Smart Workflows - Dan Diebolt
Building Smart Workflows - Dan DieboltQuickBase, Inc.
 
Vaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UIVaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UIPeter Lehto
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best PraticesChengHui Weng
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQueryGill Cleeren
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)David Giard
 

What's hot (20)

Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
jQuery Introduction
jQuery IntroductionjQuery Introduction
jQuery Introduction
 
SharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuerySharePoint Saturday St. Louis - SharePoint & jQuery
SharePoint Saturday St. Louis - SharePoint & jQuery
 
JavaScript: DOM and jQuery
JavaScript: DOM and jQueryJavaScript: DOM and jQuery
JavaScript: DOM and jQuery
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | Edureka
 
Android training day 4
Android training day 4Android training day 4
Android training day 4
 
Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]
 
ReactJS
ReactJSReactJS
ReactJS
 
Android training day 5
Android training day 5Android training day 5
Android training day 5
 
Speed up your GWT coding with gQuery
Speed up your GWT coding with gQuerySpeed up your GWT coding with gQuery
Speed up your GWT coding with gQuery
 
jQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusionjQuery, CSS3 and ColdFusion
jQuery, CSS3 and ColdFusion
 
jQuery 1.7 Events
jQuery 1.7 EventsjQuery 1.7 Events
jQuery 1.7 Events
 
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
#SPSEMEA SharePoint & jQuery - What I wish I would have known a year ago..
 
Building Smart Workflows - Dan Diebolt
Building Smart Workflows - Dan DieboltBuilding Smart Workflows - Dan Diebolt
Building Smart Workflows - Dan Diebolt
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Vaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UIVaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UI
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best Pratices
 
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
 
J Query
J QueryJ Query
J Query
 

Viewers also liked

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 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayLesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-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 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 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 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-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
 
Angular js
Angular jsAngular js
Angular jsMindtree
 
Learn Angular JS for Beginners - Lite
Learn Angular JS for Beginners - LiteLearn Angular JS for Beginners - Lite
Learn Angular JS for Beginners - Liteayman diab
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginnersMunir Hoque
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedStéphane Bégaudeau
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 

Viewers also liked (19)

Lesson 201 14 sep13-1500-ay
Lesson 201 14 sep13-1500-ayLesson 201 14 sep13-1500-ay
Lesson 201 14 sep13-1500-ay
 
Lesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-1500-ayLesson 204 03 oct13-1500-ay
Lesson 204 03 oct13-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 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 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 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-ayLesson 302 05 jan14-1500-ay
Lesson 302 05 jan14-1500-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
 
Angular js
Angular jsAngular js
Angular js
 
Learn Angular JS for Beginners - Lite
Learn Angular JS for Beginners - LiteLearn Angular JS for Beginners - Lite
Learn Angular JS for Beginners - Lite
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginners
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 

Similar to Lesson 202 02 oct13-1800-ay

Similar to Lesson 202 02 oct13-1800-ay (20)

Jquery
JqueryJquery
Jquery
 
Jquery library
Jquery libraryJquery library
Jquery library
 
JQuery_and_Ajax.pptx
JQuery_and_Ajax.pptxJQuery_and_Ajax.pptx
JQuery_and_Ajax.pptx
 
jQuery
jQueryjQuery
jQuery
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
JavaScript Libraries
JavaScript LibrariesJavaScript Libraries
JavaScript Libraries
 
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
jQueryjQuery
jQuery
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
J query presentation
J query presentationJ query presentation
J query presentation
 
J query presentation
J query presentationJ query presentation
J query presentation
 
J query training
J query trainingJ query training
J query training
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQuery
 
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
 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
jQuery Fundamentals
jQuery FundamentalsjQuery Fundamentals
jQuery Fundamentals
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Jquery
JqueryJquery
Jquery
 
JQuery
JQueryJQuery
JQuery
 

More from 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
 

More from 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
 

Recently uploaded

MEIDUNIDADE COM JESUS PALESTRA ESPIRITA1.pptx
MEIDUNIDADE COM JESUS  PALESTRA ESPIRITA1.pptxMEIDUNIDADE COM JESUS  PALESTRA ESPIRITA1.pptx
MEIDUNIDADE COM JESUS PALESTRA ESPIRITA1.pptxMneasEntidades
 
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...baharayali
 
Sabbath Cooking seventh-day sabbath.docx
Sabbath Cooking seventh-day sabbath.docxSabbath Cooking seventh-day sabbath.docx
Sabbath Cooking seventh-day sabbath.docxdarrenguzago001
 
Genesis 1:2 - Meditate the Scripture Daily bit by bit
Genesis 1:2 - Meditate the Scripture Daily bit by bitGenesis 1:2 - Meditate the Scripture Daily bit by bit
Genesis 1:2 - Meditate the Scripture Daily bit by bitmaricelcanoynuay
 
The Revelation Chapter 4 Working Copy.docx
The Revelation Chapter 4 Working Copy.docxThe Revelation Chapter 4 Working Copy.docx
The Revelation Chapter 4 Working Copy.docxFred Gosnell
 
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...baharayali
 
+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...
+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...
+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...Amil Baba Mangal Maseeh
 
Genesis 1:7 || Meditate the Scripture daily verse by verse
Genesis 1:7  ||  Meditate the Scripture daily verse by verseGenesis 1:7  ||  Meditate the Scripture daily verse by verse
Genesis 1:7 || Meditate the Scripture daily verse by versemaricelcanoynuay
 
Flores de Mayo-history and origin we need to understand
Flores de Mayo-history and origin we need to understandFlores de Mayo-history and origin we need to understand
Flores de Mayo-history and origin we need to understandvillamilcecil909
 
NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024NoHo FUMC
 
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...baharayali
 
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...baharayali
 
Genesis 1:8 || Meditate the Scripture daily verse by verse
Genesis 1:8  ||  Meditate the Scripture daily verse by verseGenesis 1:8  ||  Meditate the Scripture daily verse by verse
Genesis 1:8 || Meditate the Scripture daily verse by versemaricelcanoynuay
 
VADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call meVADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call meshivanisharma5244
 
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...Amil Baba Naveed Bangali
 

Recently uploaded (20)

MEIDUNIDADE COM JESUS PALESTRA ESPIRITA1.pptx
MEIDUNIDADE COM JESUS  PALESTRA ESPIRITA1.pptxMEIDUNIDADE COM JESUS  PALESTRA ESPIRITA1.pptx
MEIDUNIDADE COM JESUS PALESTRA ESPIRITA1.pptx
 
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...Authentic Black magic, Kala ilam expert in UAE  and Kala ilam specialist in S...
Authentic Black magic, Kala ilam expert in UAE and Kala ilam specialist in S...
 
Sabbath Cooking seventh-day sabbath.docx
Sabbath Cooking seventh-day sabbath.docxSabbath Cooking seventh-day sabbath.docx
Sabbath Cooking seventh-day sabbath.docx
 
St. Louise de Marillac and Care of the Sick Poor
St. Louise de Marillac and Care of the Sick PoorSt. Louise de Marillac and Care of the Sick Poor
St. Louise de Marillac and Care of the Sick Poor
 
Genesis 1:2 - Meditate the Scripture Daily bit by bit
Genesis 1:2 - Meditate the Scripture Daily bit by bitGenesis 1:2 - Meditate the Scripture Daily bit by bit
Genesis 1:2 - Meditate the Scripture Daily bit by bit
 
The Revelation Chapter 4 Working Copy.docx
The Revelation Chapter 4 Working Copy.docxThe Revelation Chapter 4 Working Copy.docx
The Revelation Chapter 4 Working Copy.docx
 
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
Top Kala Jadu, Black magic expert in Faisalabad and Kala ilam specialist in S...
 
+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...
+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...
+92343-7800299 No.1 Amil baba in Pakistan amil baba in Lahore amil baba in Ka...
 
St. Louise de Marillac and Poor Children
St. Louise de Marillac and Poor ChildrenSt. Louise de Marillac and Poor Children
St. Louise de Marillac and Poor Children
 
Genesis 1:7 || Meditate the Scripture daily verse by verse
Genesis 1:7  ||  Meditate the Scripture daily verse by verseGenesis 1:7  ||  Meditate the Scripture daily verse by verse
Genesis 1:7 || Meditate the Scripture daily verse by verse
 
Flores de Mayo-history and origin we need to understand
Flores de Mayo-history and origin we need to understandFlores de Mayo-history and origin we need to understand
Flores de Mayo-history and origin we need to understand
 
Zulu - The Epistle of Ignatius to Polycarp.pdf
Zulu - The Epistle of Ignatius to Polycarp.pdfZulu - The Epistle of Ignatius to Polycarp.pdf
Zulu - The Epistle of Ignatius to Polycarp.pdf
 
NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024NoHo First Good News online newsletter May 2024
NoHo First Good News online newsletter May 2024
 
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
Famous Kala Jadu, Black magic expert in UK and Kala ilam expert in Saudi Arab...
 
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
Popular Kala Jadu, Black magic expert in Karachi and Kala jadu expert in Laho...
 
Genesis 1:8 || Meditate the Scripture daily verse by verse
Genesis 1:8  ||  Meditate the Scripture daily verse by verseGenesis 1:8  ||  Meditate the Scripture daily verse by verse
Genesis 1:8 || Meditate the Scripture daily verse by verse
 
English - The Forgotten Books of Eden.pdf
English - The Forgotten Books of Eden.pdfEnglish - The Forgotten Books of Eden.pdf
English - The Forgotten Books of Eden.pdf
 
VADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call meVADODARA CALL GIRL AVAILABLE 7568201473 call me
VADODARA CALL GIRL AVAILABLE 7568201473 call me
 
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
Famous No -1 amil baba in Hyderabad ! Best No _ Astrologer in Pakistan, UK, A...
 
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
Verified Amil baba in Pakistan Amil baba in Islamabad Famous Amil baba in Ger...
 

Lesson 202 02 oct13-1800-ay

  • 1. Unit 2: jQuery Lesson 2: Syntax and Structure October 2, 2013
  • 2. Lesson 2: jQuery and Javascript Introduction to jQuery Syntax and Structure Abstraction Pictures, Vid eo, and Media 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) • jQuery is one of the fastest ways to bring movement to a webpage and have it come to life • It’s easy to use because it’s not a programming language of its own; instead it is a library (a bunch of commonly used pieces of code), written in a programming language called Javascript • To use jQuery, you don’t need to know Javascript (we will cover this in detail in Unit 3) 3
  • 4. Recap from last time (II) • Just as a French phrase book helps us understand common phrases without knowing individual words, jQuery helps us with common features without needing to understand Javascript • jQuery takes the Javascript code needed to run each of these common features and packages them into some simple commands 4
  • 5. Three benefits of jQuery over Javascript 1. Fewer mistakes – jQuery’s simple structure makes it easier to 1 identify mistakes. Fewer mistakes means less time spent debugging! 2 2. Less code – jQuery often requires only a few lines of code in comparison to Javascript 3 1. Faster to learn – the intuitive structure makes for a more gradual learning curve. It’s one of the easiest ways to add movement to a webpage! 5
  • 6. 1 jQuery uses a consistent structure • jQuery code is usually structured the same way – that’s what makes it easy to learn! • So whether you want to zoom in on an image or make some text disappear, the structure of your code will probably be the same • It may look confusing at first, but you’ll quickly get the hang of it after you have seen it a few times 6
  • 7. 1 jQuery structure and syntax (I) jQuery code English translation $(document).ready(function() { $(pageElement).someEvent(function() { $(thingToChange).someEffect(); }); }); 7
  • 8. 1 jQuery structure and syntax (II) jQuery code $(document).ready(function() { English translation When the document is ready, do the following: $(pageElement).someEvent(function() { $(thingToChange).someEffect(); }); }); 8
  • 9. 1 jQuery structure and syntax (III) jQuery code $(document).ready(function() { $(pageElement).someEvent(function() { English translation When the document is ready, do the following: When someEvent happens to pageElement, do the following: $(thingToChange).someEffect(); }); }); 9
  • 10. 1 jQuery structure and syntax (IV) 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 }); }); 10
  • 11. 1 jQuery structure and syntax (V) jQuery code English translation $(document).ready(function() { When the document is ready, do the following: $(pageElement).someEvent(function() { $(thingToChange).someEffect(); When someEvent happens to pageElement, do the following: Make someEffect happen to thingToChange }); }); Syntax notes $(element) means “select the element” 11
  • 12. 1 jQuery structure and syntax (VI) jQuery code English translation $(document).ready(function() { When the document is ready, do the following: $(pageElement).someEvent(function() { $(thingToChange).someEffect(); When someEvent happens to pageElement, do the following: Make someEffect happen to thingToChange }); }); Syntax notes $(element) means “select the element” $(element).action() means “do this action to the element” 12
  • 13. 1 jQuery structure and syntax (VII) jQuery code English translation $(document).ready(function() { When the document is ready, do the following: $(pageElement).someEvent(function() { $(thingToChange).someEffect(); When someEvent happens to pageElement, do the following: Make someEffect happen to thingToChange }); }); Syntax notes $(element) means “select the element” $(element).action() means “do this action to the element” function() means “do the following” 13
  • 14. 2 jQuery is a simpler version of Javascript (I) • Let’s look at a live example. Say we want to have an alert pop up when the user clicks Original page After clicking the text, a popup appears 14
  • 15. 2 jQuery is a simpler version of Javascript (II) • We can enable this behavior by using either jQuery or Javascript • The effect of the two code snippets below is identical! Javascript var anchors =document.getElementsByTagName(“a”); for(var z =0; z < anchors.length; z++){ var elem = anchors[z]; elem.onclick = function(){ alert(“hello”); }; } jQuery $(document).ready(function() { $('a').click(function() { alert('hello'); }); }); 15
  • 16. 2 jQuery is a simpler version of Javascript (III) • As you can see, parts of the code are the same, but the jQuery version removes a lot of the complexity that you get with Javascript Javascript jQuery var anchors =document.getElementsByTagName(“a”); for(var z =0; z < anchors.length; z++){ var elem = anchors[z]; elem.onclick = function(){ alert(“hello”); }; } $(document).ready(function() { $('a').click(function() { alert('hello'); }); }); The code triggering the alert is identical 16
  • 17. 3 Translating jQuery into English (I) jQuery code English translation $(document).ready(function() { $('a').click(function() { alert('hello'); }); }); Syntax notes 17
  • 18. 3 Translating jQuery into English (II) jQuery code $(document).ready(function() { English translation When the document is ready, do the following: $('a').click(function() { alert('hello'); }); }); Syntax notes 18
  • 19. 3 Translating jQuery into English (III) jQuery code $(document).ready(function() { $('a').click(function() { English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: alert('hello'); }); }); Syntax notes 19
  • 20. 3 Translating jQuery into English (IV) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” }); }); Syntax notes 20
  • 21. 3 Translating jQuery into English (V) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” }); }); Syntax notes $(element) means “select the element” 21
  • 22. 3 Translating jQuery into English (VI) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” }); }); Syntax notes $(element) means “select the element” $(element).action() means “do this action to the element” 22
  • 23. 3 Translating jQuery into English (VII) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” }); }); Syntax notes $(element) means “select the element” $(element).action() means “do this action to the element” function() means “do the following” 23
  • 24. 3 Translating jQuery into English (VII) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); }); }); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” 24
  • 25. 3 Translating jQuery into English (VII) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); }); }); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” Original page Result after clicking 25
  • 26. Summary (I) • jQuery has three main benefits over Javascript: 1) Fewer mistakes 2) Less code 3) Faster to learn • jQuery code has a consistent structure jQuery code $(document).ready(function() { $(pageElement).someEvent(function() { $(thingToChange).someEffect(); }); }); 26
  • 27. Summary (II) • jQuery has three main benefits over Javascript: 1) Fewer mistakes 2) Less code 3) Faster to learn • jQuery code has a consistent structure 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 }); }); 27
  • 28. Summary (III) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); }); }); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” 28
  • 29. Summary (IV) jQuery code $(document).ready(function() { $('a').click(function() { alert('hello'); }); }); English translation When the document is ready, do the following: When the HTML element with an <a> tag is clicked, do the following: Send an alert that says “hello” Original page Result after clicking 29
  • 30. 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 30