SlideShare a Scribd company logo
Introduction to JQuery
Dr Andres Baravalle
Outline
• Functions and variable scope (cont'd)
• Constructors
• Methods
• Using Ajax libraries: jQuery
Functions and variable scope
(cont'd)
Activity #1: using functions
Analyse the following code:
<script type="text/javascript">
var total = 0;
var number = 0;
while(number!=".") {
total += parseInt(number);
number = prompt("Add a list of numbers. Type a number or '.'
to exit.","");
}
alert("The total is: " + total);
</script>
Activity #1: using functions (2)
• After you've understood the mechanics of
the short code, rewrite the code to use a
function
– Normally, you wouldn't need a function in
such a case – this is just to get you started
Activity #2: variable scope
• Analyse the code in the next page
– Try to determine what should happen
– Then run the code and see what actually
happens.
Activity #2: variable scope (2)
var number = 200;
incNumber(number);
alert("The first value of number is: " + number);
function incNumber(number) {
// what is the value of number here?
number++;
}
// what is the value of number here?
number++;
alert("The second value of number is: " + number);
incNumber(number);
// what is the value of number here?
alert("The third value of number is: " + number);
Constructors
Creating objects
• You can create (basic) objects directly:
var andres = {"name": "Andres",
"surname": "Baravalle",
"address": "Snaresbrook",
"user_id": "andres2" };
• The problem of such an approach is that it
can be a lengthy process to create a
number of objects with different values.
Constructors
• Constructors are a special type of function
that can be used to create objects in a
more efficient way.
Using constructors
• The problem of the approach we have just
seen is that it can be a lengthy process to
create a number of objects with different
values
• Using constructor functions can make the
process faster.
Using constructors (2)
• The code becomes shorter and neater to maintain:
function Staff(name, surname, address, user_id, year_of_birth) {
this.name = name;
this.surname = surname;
this.address = address;
this.user_id = user_id;
this.year_of_birth = year_of_birth;
}
var andres = new Staff("Andres", "Baravalle", "East London", "andres2");
console.log(andres); // let's use with firebug for debugging!
Using construtors (+Firebug)
Activity #3
• Adapt the Staff() constructor to create a
constructor for students
• Record all the information in Staff(), plus year of
registration and list of modules attended (as an
array)
• Create 2 students objects to demonstrate the
use of your constructor
Activity #4
• Building on top of Activity #3, add an extra
property, marks
• Marks will be an object itself
– Please create the marks object without a
constructor
• Demonstrate the new property
Methods
• Methods are functions associated with
objects.
• In the next slide we'll modify again our
class, as an example to illustrate what this
means
Using methods
function staff (name, surname, address, user_id, year_of_birth) {
this.name = name;
this.surname = surname;
this.address = address;
this.user_id = user_id;
this.year_of_birth = year_of_birth;
this.calculateAge = calculateAge; // use the name of the function to link here
this.age = this.calculateAge(); // calling calculateAge *inside* this function context
}
function calculateAge() {
// "this" works as we have linked the constructor with this function
return year - this.year_of_birth;
}
year = 2013;
var andres = new staff("Andres", "Baravalle", "East London", "andres2", 1976);
console.log(andres); // use with firebug for debugging!
Activity #5: Using methods
• Adapt your student class to store the
mean mark using an extra class variable,
mean_mark, and an extra method,
calculateMeanMark()
– Use for … in statement to navigate the mark
(see http://baravalle.it/javascript-
guide/#for_Statement)
Using Ajax libraries
Web 2.0
• Web 2.0 is one of neologisms commonly
in use in the Web community. According to
Tim O’Reilly, Web 2.0 refers to:
– "the business revolution in the computer
industry caused by the move to the internet as
platform, and an attempt to understand the
rules for success on that new platform"
(http://radar.oreilly.com/archives/2006/1
2/web_20_compact.html).
Web 2.0 (2)
• The idea of Web 2.0 is as an incremental step from Web
1.0.
– It is based on Web 1.0, but with something more
• The concept of ‘internet as a platform’ implies that Web
2.0 is based on the Web on its own as place where
applications run
– The browser allows applications to run on any host operating
system.
– In the Web 2.0 strategy, we move from writing a version of
software for every operating system that has to be supported, to
writing a Web application that will automatically run on any
operating system where you can run a suitable browser.
Web 2.0 technologies
• Technologies such as Ajax (Asynchronous
JavaScript and XML; we will explore that
further in this study guide), RSS (an XML
dialect used for content syndication), Atom
(another XML dialect used for content
syndication) and SOAP (an XML dialect
used for message exchange) are all
typically associated with Web 2.0.
What is Ajax?
• Ajax is considered to be one of the most
important building blocks for Web 2.0
applications.
• Both JavaScript and XML existed before Web
2.0 – the innovation of Ajax is to combine these
technologies together to create more interactive
Web applications.
• Ajax is typically used to allow interactions
between client and server without having to
reload a Web page.
Ajax libraries
• A number of different libraries have been developed in
the last few years to support a faster and more
integrated development of Ajax applications.
• jQuery (http://jquery.com), Spry
(http://labs.adobe.com/technologies/spry),
Script.aculo.us (http://script.aculo.us) and Dojo
(http://dojotoolkit.org) are some of the more commonly
used Ajax frameworks.
– Spry is included in Dreamweaver – and is an easy option to start
– We are going to use a quite advanced library – jQuery – even
tough we'll do that at a basic level
jQuery
• jQuery is a JavaScript library designed to
simplify the development of multi-platform
client-side scripts
• jQuery's makes it easy(-ish?) to navigate a
document, select DOM elements, create
animations, handle events, and develop
Ajax applications.
– and it's free, open source software!
jQuery – let's start
• As a first step, you'll need to download the
jQuery library from jquery.com
• For development, you should use the
"normal" (non-minified) js file file in the
library
– A minified version also exists – it removes
spaces, newlines, comments and shortens
some variable names to make the file size
smaller (for deployment only)
jQuery CDN
• You can also use jQuery through a CDN (content
delivery network), including the file directly:
http://code.jquery.com/jquery-1.8.1.min.js (normally for
deployment, not development)
• Using the CDN version normally allows a better
experience to users – as they might have already the
library in cache from a visit to another site also using the
same CDN
• You should not use CDN for development – only in
production
jQuery commands
• jQuery commands begin with a call to the
jQuery function or its alias.
jQuery commands (2)
• jQuery comes with a shorthand function -
$().
• You'll normally use $() instead of the
jQuery() function
– $() is not defined in JavaScript – is just a
function having a 1 letter name, defined in
jQuery
jQuery commands (3)
• You normally run your jQuery commands
after your page has been loaded:
$(document).ready(function() {
alert(Hey, this works!);
});
jQuery selectors
• You can "select" elements with the same
syntax that you have been using to travers
the DOM in CSS
• E.g.
– $('tr')
– $('#celebs')
– $('.data')
– $('div.fancy p span')
Reading properties
• You can use jQuery to read properties
• E.g.
$(document).ready(function() {
var fontSize = $('body p').css('font-size');
alert(fontSize);
});
Changing properties
• You can use the same syntax to change
properties:
$('p#first').css('font-color','red');
• You can use arrays too!
$('body p').css(
{'background-color': '#dddddd',
'color': '#666666',
'font-size': '11pt})
});
Hey, that's handy!
Dreamweaver will help you!
• As you can see, Dreamweaver
understands jQuery!
• Dreamweaver ships with autocomplete
functions and syntax highlighting for
jQuery
– and Aptana too!
Activity #6: starting with CSS
• Download the jQuery library and include it
in a new HTML file
• Use a "lorem ipsum" text as usual to fill
your page with a few paragraphs
• Try out basic jQuery commands to change
the style of the paragraphs
Sorry – isn't this useless?
• Yes! What you have tried up to now is
useless on its own – you could do the
same with just css
• In the next slides we'll see a better use of
jQuery
Activity #7: hiding and showing
elements
• Analyse the code at
http://baravalle.com/presentations/ske6/ac
tivities/javascript/jquery_hide_paragraph.h
tml
• You have an anonymous (=without a
name) function applied to the onclick
event of the element #a1
• That means that the function will run when
you click on #a1
Activity #7: hiding and showing
elements (2)
• Building on top of the existing code, write
a number of additional anonymous
functions to hide/show the other
paragraphs
Adding HTML: after()
• You can also add child nodes:
$('#second').after("<p>Hey, this is a new paragraph!</p>");
• When clicking on the item with id=a1 (#a1
should be an anchor, as in the previous
example), add some HTML after item #second
• See in action at
http://baravalle.com/presentations/ske6/activities
/javascript/jquery_new_paragraph.html
Adding HTML (insertAfter())
• You can insert HTML after a specific
selector:
$("<p>Hey, this is a new paragraph!
</p>").insertAfter('#second');
Working on more selectors
• You can work on many selectors at the
same time:
$('#second, #third').after("<p>Hey, this
is a new paragraph!</p>");
Activity #8
• Build on top of your previous code to
dynamically add new content to your
page, using after() or insertAfter()
Removing elements
• You can also remove elements:
$('p').remove(':contains("Hey, this is a new
paragraph!")');
• or replace their content:
$('p').html('Replacing all paragraphs!');
Animations: fadeout()
• You can animate any element:
$('#first').fadeOut();
Animations: using the padding
• You can edit properties of your selectors
and animate them:
$('#third').animate({
paddingLeft: '+=15px'
}, 200);
• Please note that animate() requires you to
write the property name in camel case
(paddingLeft rather than the usual
padding-left)
Activity #9: using plugins
• jQuery includes a large number of plugins
• Read the documentation for the color-
animation plugin:
http://www.bitstorm.org/jquery/color-
animation/
– Embed the plugin in your page
– and animate a paragraph!
Chaining
• Remember that you can chain different
jQuery methods:
• $
('p:last').slideDown('slow').delay(200).fade
Out();
And now it's the end
• You should be ready to use HTML, CSS,
JavaScript, jQuery and PHP – at least to
some degree
Ad

More Related Content

What's hot (20)

Intro to Web Application Security
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application Security
Rob Ragan
 
All about email
All about emailAll about email
All about email
estefana4
 
Firewall
FirewallFirewall
Firewall
Muhammad Sohaib Afzaal
 
public key infrastructure
public key infrastructurepublic key infrastructure
public key infrastructure
vimal kumar
 
What is Cryptography and Types of attacks in it
What is Cryptography and Types of attacks in itWhat is Cryptography and Types of attacks in it
What is Cryptography and Types of attacks in it
lavakumar Thatisetti
 
Internet security software
Internet security softwareInternet security software
Internet security software
university of education,Lahore
 
Information Security (Digital Signatures)
Information Security (Digital Signatures)Information Security (Digital Signatures)
Information Security (Digital Signatures)
Zara Nawaz
 
Security Vulnerabilities
Security VulnerabilitiesSecurity Vulnerabilities
Security Vulnerabilities
Marius Vorster
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
Shivanand Arur
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
yht4ever
 
Email security presentation
Email security presentationEmail security presentation
Email security presentation
SubhradeepMaji
 
Network Security Presentation
Network Security PresentationNetwork Security Presentation
Network Security Presentation
Allan Pratt MBA
 
Spoofing
SpoofingSpoofing
Spoofing
Sanjeev
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
OECLIB Odisha Electronics Control Library
 
XML Schema
XML SchemaXML Schema
XML Schema
Kumar
 
Xml ppt
Xml pptXml ppt
Xml ppt
seemadav1
 
Firewall
FirewallFirewall
Firewall
nayakslideshare
 
Jquery
JqueryJquery
Jquery
Girish Srivastava
 
Print server
Print serverPrint server
Print server
catacutanjcsantos
 
Web security
Web securityWeb security
Web security
Muhammad Usman
 

Viewers also liked (18)

Social, professional, ethical and legal issues
Social, professional, ethical and legal issuesSocial, professional, ethical and legal issues
Social, professional, ethical and legal issues
Andres Baravalle
 
Other metrics
Other metricsOther metrics
Other metrics
Andres Baravalle
 
Accessibility introduction
Accessibility introductionAccessibility introduction
Accessibility introduction
Andres Baravalle
 
Designing and prototyping
Designing and prototypingDesigning and prototyping
Designing and prototyping
Andres Baravalle
 
Background on Usability Engineering
Background on Usability EngineeringBackground on Usability Engineering
Background on Usability Engineering
Andres Baravalle
 
Issue-based metrics
Issue-based metricsIssue-based metrics
Issue-based metrics
Andres Baravalle
 
Interfaces
InterfacesInterfaces
Interfaces
Andres Baravalle
 
Usability evaluations (part 2)
Usability evaluations (part 2) Usability evaluations (part 2)
Usability evaluations (part 2)
Andres Baravalle
 
Usability evaluations (part 3)
Usability evaluations (part 3) Usability evaluations (part 3)
Usability evaluations (part 3)
Andres Baravalle
 
Accessibility: introduction
Accessibility: introduction  Accessibility: introduction
Accessibility: introduction
Andres Baravalle
 
Measuring the user experience
Measuring the user experienceMeasuring the user experience
Measuring the user experience
Andres Baravalle
 
Usability evaluation methods (part 2) and performance metrics
Usability evaluation methods (part 2) and performance metricsUsability evaluation methods (part 2) and performance metrics
Usability evaluation methods (part 2) and performance metrics
Andres Baravalle
 
SPEL (Social, professional, ethical and legal) issues in Usability
SPEL (Social, professional, ethical and legal) issues in UsabilitySPEL (Social, professional, ethical and legal) issues in Usability
SPEL (Social, professional, ethical and legal) issues in Usability
Andres Baravalle
 
Design rules and usability requirements
Design rules and usability requirementsDesign rules and usability requirements
Design rules and usability requirements
Andres Baravalle
 
Planning and usability evaluation methods
Planning and usability evaluation methodsPlanning and usability evaluation methods
Planning and usability evaluation methods
Andres Baravalle
 
Don't make me think
Don't make me thinkDon't make me think
Don't make me think
Andres Baravalle
 
Dark web markets: from the silk road to alphabay, trends and developments
Dark web markets: from the silk road to alphabay, trends and developmentsDark web markets: from the silk road to alphabay, trends and developments
Dark web markets: from the silk road to alphabay, trends and developments
Andres Baravalle
 
Layout rules
Layout rulesLayout rules
Layout rules
mangal das
 
Social, professional, ethical and legal issues
Social, professional, ethical and legal issuesSocial, professional, ethical and legal issues
Social, professional, ethical and legal issues
Andres Baravalle
 
Accessibility introduction
Accessibility introductionAccessibility introduction
Accessibility introduction
Andres Baravalle
 
Background on Usability Engineering
Background on Usability EngineeringBackground on Usability Engineering
Background on Usability Engineering
Andres Baravalle
 
Usability evaluations (part 2)
Usability evaluations (part 2) Usability evaluations (part 2)
Usability evaluations (part 2)
Andres Baravalle
 
Usability evaluations (part 3)
Usability evaluations (part 3) Usability evaluations (part 3)
Usability evaluations (part 3)
Andres Baravalle
 
Accessibility: introduction
Accessibility: introduction  Accessibility: introduction
Accessibility: introduction
Andres Baravalle
 
Measuring the user experience
Measuring the user experienceMeasuring the user experience
Measuring the user experience
Andres Baravalle
 
Usability evaluation methods (part 2) and performance metrics
Usability evaluation methods (part 2) and performance metricsUsability evaluation methods (part 2) and performance metrics
Usability evaluation methods (part 2) and performance metrics
Andres Baravalle
 
SPEL (Social, professional, ethical and legal) issues in Usability
SPEL (Social, professional, ethical and legal) issues in UsabilitySPEL (Social, professional, ethical and legal) issues in Usability
SPEL (Social, professional, ethical and legal) issues in Usability
Andres Baravalle
 
Design rules and usability requirements
Design rules and usability requirementsDesign rules and usability requirements
Design rules and usability requirements
Andres Baravalle
 
Planning and usability evaluation methods
Planning and usability evaluation methodsPlanning and usability evaluation methods
Planning and usability evaluation methods
Andres Baravalle
 
Dark web markets: from the silk road to alphabay, trends and developments
Dark web markets: from the silk road to alphabay, trends and developmentsDark web markets: from the silk road to alphabay, trends and developments
Dark web markets: from the silk road to alphabay, trends and developments
Andres Baravalle
 
Ad

Similar to Introduction to jQuery (20)

Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
Balint Erdi
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
PraveenKumar680401
 
JS & NodeJS - An Introduction
JS & NodeJS - An IntroductionJS & NodeJS - An Introduction
JS & NodeJS - An Introduction
Nirvanic Labs
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Gil Irizarry
 
Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
SANTOSH RATH
 
Javascript pdf for beginners easy levell
Javascript pdf for beginners easy levellJavascript pdf for beginners easy levell
Javascript pdf for beginners easy levell
SakshamGupta957136
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
Make Mobile Apps Quickly
Make Mobile Apps QuicklyMake Mobile Apps Quickly
Make Mobile Apps Quickly
Gil Irizarry
 
J query presentation
J query presentationJ query presentation
J query presentation
sawarkar17
 
J query presentation
J query presentationJ query presentation
J query presentation
akanksha17
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfgNEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
Syed Moosa Kaleem
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
Jayanga V. Liyanage
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.ppt
Lalith86
 
IP Unit 2.pptx
IP Unit 2.pptxIP Unit 2.pptx
IP Unit 2.pptx
Vigneshkumar Ponnusamy
 
Intro to .NET for Government Developers
Intro to .NET for Government DevelopersIntro to .NET for Government Developers
Intro to .NET for Government Developers
Frank La Vigne
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
Bilal Ahmed
 
JS & NodeJS - An Introduction
JS & NodeJS - An IntroductionJS & NodeJS - An Introduction
JS & NodeJS - An Introduction
Nirvanic Labs
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Gil Irizarry
 
Iwt note(module 2)
Iwt note(module 2)Iwt note(module 2)
Iwt note(module 2)
SANTOSH RATH
 
Javascript pdf for beginners easy levell
Javascript pdf for beginners easy levellJavascript pdf for beginners easy levell
Javascript pdf for beginners easy levell
SakshamGupta957136
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 
Make Mobile Apps Quickly
Make Mobile Apps QuicklyMake Mobile Apps Quickly
Make Mobile Apps Quickly
Gil Irizarry
 
J query presentation
J query presentationJ query presentation
J query presentation
sawarkar17
 
J query presentation
J query presentationJ query presentation
J query presentation
akanksha17
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfgNEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
Syed Moosa Kaleem
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia
 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
javascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.pptjavascript Event Handling and introduction to event.ppt
javascript Event Handling and introduction to event.ppt
Lalith86
 
Intro to .NET for Government Developers
Intro to .NET for Government DevelopersIntro to .NET for Government Developers
Intro to .NET for Government Developers
Frank La Vigne
 
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
Bilal Ahmed
 
Ad

More from Andres Baravalle (7)

Don’t make me think
Don’t make me thinkDon’t make me think
Don’t make me think
Andres Baravalle
 
Data collection and analysis
Data collection and analysisData collection and analysis
Data collection and analysis
Andres Baravalle
 
Interaction design and cognitive aspects
Interaction design and cognitive aspects Interaction design and cognitive aspects
Interaction design and cognitive aspects
Andres Baravalle
 
Designing and prototyping
Designing and prototypingDesigning and prototyping
Designing and prototyping
Andres Baravalle
 
Usability requirements
Usability requirements Usability requirements
Usability requirements
Andres Baravalle
 
Usability: introduction (Week 1)
Usability: introduction (Week 1)Usability: introduction (Week 1)
Usability: introduction (Week 1)
Andres Baravalle
 
Don’t make me think!
Don’t make me think!Don’t make me think!
Don’t make me think!
Andres Baravalle
 
Data collection and analysis
Data collection and analysisData collection and analysis
Data collection and analysis
Andres Baravalle
 
Interaction design and cognitive aspects
Interaction design and cognitive aspects Interaction design and cognitive aspects
Interaction design and cognitive aspects
Andres Baravalle
 
Usability: introduction (Week 1)
Usability: introduction (Week 1)Usability: introduction (Week 1)
Usability: introduction (Week 1)
Andres Baravalle
 

Recently uploaded (20)

Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 

Introduction to jQuery

  • 1. Introduction to JQuery Dr Andres Baravalle
  • 2. Outline • Functions and variable scope (cont'd) • Constructors • Methods • Using Ajax libraries: jQuery
  • 3. Functions and variable scope (cont'd)
  • 4. Activity #1: using functions Analyse the following code: <script type="text/javascript"> var total = 0; var number = 0; while(number!=".") { total += parseInt(number); number = prompt("Add a list of numbers. Type a number or '.' to exit.",""); } alert("The total is: " + total); </script>
  • 5. Activity #1: using functions (2) • After you've understood the mechanics of the short code, rewrite the code to use a function – Normally, you wouldn't need a function in such a case – this is just to get you started
  • 6. Activity #2: variable scope • Analyse the code in the next page – Try to determine what should happen – Then run the code and see what actually happens.
  • 7. Activity #2: variable scope (2) var number = 200; incNumber(number); alert("The first value of number is: " + number); function incNumber(number) { // what is the value of number here? number++; } // what is the value of number here? number++; alert("The second value of number is: " + number); incNumber(number); // what is the value of number here? alert("The third value of number is: " + number);
  • 9. Creating objects • You can create (basic) objects directly: var andres = {"name": "Andres", "surname": "Baravalle", "address": "Snaresbrook", "user_id": "andres2" }; • The problem of such an approach is that it can be a lengthy process to create a number of objects with different values.
  • 10. Constructors • Constructors are a special type of function that can be used to create objects in a more efficient way.
  • 11. Using constructors • The problem of the approach we have just seen is that it can be a lengthy process to create a number of objects with different values • Using constructor functions can make the process faster.
  • 12. Using constructors (2) • The code becomes shorter and neater to maintain: function Staff(name, surname, address, user_id, year_of_birth) { this.name = name; this.surname = surname; this.address = address; this.user_id = user_id; this.year_of_birth = year_of_birth; } var andres = new Staff("Andres", "Baravalle", "East London", "andres2"); console.log(andres); // let's use with firebug for debugging!
  • 14. Activity #3 • Adapt the Staff() constructor to create a constructor for students • Record all the information in Staff(), plus year of registration and list of modules attended (as an array) • Create 2 students objects to demonstrate the use of your constructor
  • 15. Activity #4 • Building on top of Activity #3, add an extra property, marks • Marks will be an object itself – Please create the marks object without a constructor • Demonstrate the new property
  • 16. Methods • Methods are functions associated with objects. • In the next slide we'll modify again our class, as an example to illustrate what this means
  • 17. Using methods function staff (name, surname, address, user_id, year_of_birth) { this.name = name; this.surname = surname; this.address = address; this.user_id = user_id; this.year_of_birth = year_of_birth; this.calculateAge = calculateAge; // use the name of the function to link here this.age = this.calculateAge(); // calling calculateAge *inside* this function context } function calculateAge() { // "this" works as we have linked the constructor with this function return year - this.year_of_birth; } year = 2013; var andres = new staff("Andres", "Baravalle", "East London", "andres2", 1976); console.log(andres); // use with firebug for debugging!
  • 18. Activity #5: Using methods • Adapt your student class to store the mean mark using an extra class variable, mean_mark, and an extra method, calculateMeanMark() – Use for … in statement to navigate the mark (see http://baravalle.it/javascript- guide/#for_Statement)
  • 20. Web 2.0 • Web 2.0 is one of neologisms commonly in use in the Web community. According to Tim O’Reilly, Web 2.0 refers to: – "the business revolution in the computer industry caused by the move to the internet as platform, and an attempt to understand the rules for success on that new platform" (http://radar.oreilly.com/archives/2006/1 2/web_20_compact.html).
  • 21. Web 2.0 (2) • The idea of Web 2.0 is as an incremental step from Web 1.0. – It is based on Web 1.0, but with something more • The concept of ‘internet as a platform’ implies that Web 2.0 is based on the Web on its own as place where applications run – The browser allows applications to run on any host operating system. – In the Web 2.0 strategy, we move from writing a version of software for every operating system that has to be supported, to writing a Web application that will automatically run on any operating system where you can run a suitable browser.
  • 22. Web 2.0 technologies • Technologies such as Ajax (Asynchronous JavaScript and XML; we will explore that further in this study guide), RSS (an XML dialect used for content syndication), Atom (another XML dialect used for content syndication) and SOAP (an XML dialect used for message exchange) are all typically associated with Web 2.0.
  • 23. What is Ajax? • Ajax is considered to be one of the most important building blocks for Web 2.0 applications. • Both JavaScript and XML existed before Web 2.0 – the innovation of Ajax is to combine these technologies together to create more interactive Web applications. • Ajax is typically used to allow interactions between client and server without having to reload a Web page.
  • 24. Ajax libraries • A number of different libraries have been developed in the last few years to support a faster and more integrated development of Ajax applications. • jQuery (http://jquery.com), Spry (http://labs.adobe.com/technologies/spry), Script.aculo.us (http://script.aculo.us) and Dojo (http://dojotoolkit.org) are some of the more commonly used Ajax frameworks. – Spry is included in Dreamweaver – and is an easy option to start – We are going to use a quite advanced library – jQuery – even tough we'll do that at a basic level
  • 25. jQuery • jQuery is a JavaScript library designed to simplify the development of multi-platform client-side scripts • jQuery's makes it easy(-ish?) to navigate a document, select DOM elements, create animations, handle events, and develop Ajax applications. – and it's free, open source software!
  • 26. jQuery – let's start • As a first step, you'll need to download the jQuery library from jquery.com • For development, you should use the "normal" (non-minified) js file file in the library – A minified version also exists – it removes spaces, newlines, comments and shortens some variable names to make the file size smaller (for deployment only)
  • 27. jQuery CDN • You can also use jQuery through a CDN (content delivery network), including the file directly: http://code.jquery.com/jquery-1.8.1.min.js (normally for deployment, not development) • Using the CDN version normally allows a better experience to users – as they might have already the library in cache from a visit to another site also using the same CDN • You should not use CDN for development – only in production
  • 28. jQuery commands • jQuery commands begin with a call to the jQuery function or its alias.
  • 29. jQuery commands (2) • jQuery comes with a shorthand function - $(). • You'll normally use $() instead of the jQuery() function – $() is not defined in JavaScript – is just a function having a 1 letter name, defined in jQuery
  • 30. jQuery commands (3) • You normally run your jQuery commands after your page has been loaded: $(document).ready(function() { alert(Hey, this works!); });
  • 31. jQuery selectors • You can "select" elements with the same syntax that you have been using to travers the DOM in CSS • E.g. – $('tr') – $('#celebs') – $('.data') – $('div.fancy p span')
  • 32. Reading properties • You can use jQuery to read properties • E.g. $(document).ready(function() { var fontSize = $('body p').css('font-size'); alert(fontSize); });
  • 33. Changing properties • You can use the same syntax to change properties: $('p#first').css('font-color','red'); • You can use arrays too! $('body p').css( {'background-color': '#dddddd', 'color': '#666666', 'font-size': '11pt}) });
  • 35. Dreamweaver will help you! • As you can see, Dreamweaver understands jQuery! • Dreamweaver ships with autocomplete functions and syntax highlighting for jQuery – and Aptana too!
  • 36. Activity #6: starting with CSS • Download the jQuery library and include it in a new HTML file • Use a "lorem ipsum" text as usual to fill your page with a few paragraphs • Try out basic jQuery commands to change the style of the paragraphs
  • 37. Sorry – isn't this useless? • Yes! What you have tried up to now is useless on its own – you could do the same with just css • In the next slides we'll see a better use of jQuery
  • 38. Activity #7: hiding and showing elements • Analyse the code at http://baravalle.com/presentations/ske6/ac tivities/javascript/jquery_hide_paragraph.h tml • You have an anonymous (=without a name) function applied to the onclick event of the element #a1 • That means that the function will run when you click on #a1
  • 39. Activity #7: hiding and showing elements (2) • Building on top of the existing code, write a number of additional anonymous functions to hide/show the other paragraphs
  • 40. Adding HTML: after() • You can also add child nodes: $('#second').after("<p>Hey, this is a new paragraph!</p>"); • When clicking on the item with id=a1 (#a1 should be an anchor, as in the previous example), add some HTML after item #second • See in action at http://baravalle.com/presentations/ske6/activities /javascript/jquery_new_paragraph.html
  • 41. Adding HTML (insertAfter()) • You can insert HTML after a specific selector: $("<p>Hey, this is a new paragraph! </p>").insertAfter('#second');
  • 42. Working on more selectors • You can work on many selectors at the same time: $('#second, #third').after("<p>Hey, this is a new paragraph!</p>");
  • 43. Activity #8 • Build on top of your previous code to dynamically add new content to your page, using after() or insertAfter()
  • 44. Removing elements • You can also remove elements: $('p').remove(':contains("Hey, this is a new paragraph!")'); • or replace their content: $('p').html('Replacing all paragraphs!');
  • 45. Animations: fadeout() • You can animate any element: $('#first').fadeOut();
  • 46. Animations: using the padding • You can edit properties of your selectors and animate them: $('#third').animate({ paddingLeft: '+=15px' }, 200); • Please note that animate() requires you to write the property name in camel case (paddingLeft rather than the usual padding-left)
  • 47. Activity #9: using plugins • jQuery includes a large number of plugins • Read the documentation for the color- animation plugin: http://www.bitstorm.org/jquery/color- animation/ – Embed the plugin in your page – and animate a paragraph!
  • 48. Chaining • Remember that you can chain different jQuery methods: • $ ('p:last').slideDown('slow').delay(200).fade Out();
  • 49. And now it's the end • You should be ready to use HTML, CSS, JavaScript, jQuery and PHP – at least to some degree