SlideShare a Scribd company logo
Web Application Architectures
Module 6: Presentation/User Interface
Lecture 7: JavaScript & JQuery
c 2011-13 G.L. Heileman Module 6, Lecture 7 1 / 9
JavaScript
JavaScript is a lightweight, interpreted programming language that
was designed to be embedded within, and provide scripting capabilities
to, any application.
A scripting language is used to write “scripts” that are distinct from
the core code of an application. Scripts are often written in a
language that is different from that of the core application, and they
are typically intended to be created/modified by end users.
Client-side JavaScript combines the scripting capabilities of the
JavaScript interpreter with the document object model (DOM) defined
in a web browser, enabling executable content to be distributed over
the web. All major browsers include a JavaScript interpreter (engine).
c 2011-13 G.L. Heileman Module 6, Lecture 7 2 / 9
JavaScript
It is also possible to run JavaScript in other environments.
Ex. Node.js is a server-side JavaScript application for developing
networking applications.
JavaScript is primarily used to write functions that are embedded in or
included from HTML pages delivered by a web server, for the purpose
of dynamically modifying the HTML elements on client-side pages
through the DOM.
Because JavaScript code runs locally in the browser, it can quickly
respond to user actions, making the web application as a whole more
responsive.
Ex. JavaScript can be used to update a portion of webpage, or to
perform client-side validations, prior to submitting form data to the
web application.
c 2011-13 G.L. Heileman Module 6, Lecture 7 3 / 9
The JavaScript Language
The syntax of the JavaScript language is highly influenced by C;
however JavaScript is actually a multi-paradigm language, supporting
the prototype-based, functional, imperative and scripting approaches
to programming.
It’s easy to access the JavaScript interpreter in your browser:
– Put JavaScript code in an HTML file, enclosed within the <script>
tag, and render the file in your browser.
– Use the JavaScript console provided as a part of the “developer tools”
that come with your browser.
c 2011-13 G.L. Heileman Module 6, Lecture 7 4 / 9
JavaScript Interpreters
Consider the recurrence relation for computing the Fibonacci numbers:
F(n) =



0, if n = 0
1, if n = 1
F(n − 1) + F(n − 2), if n > 1
Create a file fib.html, containing the following JavaScript code:
<script>
document.write("<h2>Table of Fibonacci Numbers</h2>");
for (i=0, j=1, k=0, f=0; i<50; i++, f=j+k, j=k, k=f) {
document.write("Fibonacci (" + i + ") = " + f);
document.write("<br>");
}
</script>
To execute this code, in your browser address bar type:
file://<path_to_file>/fib.html
c 2011-13 G.L. Heileman Module 6, Lecture 7 5 / 9
JavaScript and Browser Security
Client-side JavaScript opens up the possibility for authors to deliver
malicious scripts to the browser.
Browsers guard against this using two strategies:
– JavaScript code is run in a sandbox that only allows web-related
actions to be performed, not general-purpose programming tasks (no
writing to disk, creating files, etc.).
– JavaScript code is constrained by the same origin policy – scripts from
one website do not have access to information such as usernames,
passwords, or cookies from other websites.
c 2011-13 G.L. Heileman Module 6, Lecture 7 6 / 9
JavaScript Libraries
Numerous JavaScript libraries, containing pre-written JavaScript code,
have been developed for the purpose of making the the development
of JavaScript-based web applications easier.
The most popular JavaScript library is jQuery, and it is now supported
by default in Rails.
An entire ecosystem has built up around jQuery, including companion
libraries (e.g., jQuery UI) and plug-ins (both official and unofficial).
jQuery supports the notion of unobtrusive JavaScript – the separation
of behavior from document structure. With unobtrusive JavaScript,
you never embed any JavaScript expressions or statements within the
body of an HTML document, either as attributes of HTML elements
(such as onclick) or in script blocks.
c 2011-13 G.L. Heileman Module 6, Lecture 7 7 / 9
jQuery
The jQuery developers placed a high priority on ensuring that it
worked consistently across all major browsers.
The focus in jQuery is on retrieving elements from HTML pages, and
performing operation on them.
Elements are retrieved via selectors, using the same selectors that are
in CSS. To collect a group of elements, you pass the selector to the
jQuery function as follows:
jQuery(<selector>)
You will more likely encounter the shortcut version of this function call:
$(<selector>)
This function returns a JavaScript object containing an array of DOM
elements that match the selector.
c 2011-13 G.L. Heileman Module 6, Lecture 7 8 / 9
jQuery
The returned elements are actually “wrapped” with additional
functions (methods), and these elements are therefore referred to as
the wrapped set. Available methods: api.jquery.com.
Ex.
$("div.byebye").hide();
This will hide all of the div elements in the document that belong to
the class bye-bye.
Many of the jQuery methods also return a wrapped set, so it’s
common to chain methods in jQuery.
Ex.
$("div.byebye").hide().addClass("removed");
This will add a new class, called removed, to the hidden div
elements.
c 2011-13 G.L. Heileman Module 6, Lecture 7 9 / 9
Ad

More Related Content

What's hot (20)

Drupalgeddon 2 Null_meet
Drupalgeddon 2 Null_meetDrupalgeddon 2 Null_meet
Drupalgeddon 2 Null_meet
Dhaval Khairnar
 
Wpf 1
Wpf 1Wpf 1
Wpf 1
Fajar Baskoro
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
Edureka!
 
JavaScript: Implementations And Applications
JavaScript: Implementations And ApplicationsJavaScript: Implementations And Applications
JavaScript: Implementations And Applications
Pragya Pai
 
Codeigniter Introduction
Codeigniter IntroductionCodeigniter Introduction
Codeigniter Introduction
Ashfan Ahamed
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
Vijay Kumar Verma
 
Chapter1 introduction to asp.net
Chapter1  introduction to asp.netChapter1  introduction to asp.net
Chapter1 introduction to asp.net
mentorrbuddy
 
CodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.com
Christopher Cubos
 
Polyglot Mule Transformers
Polyglot Mule TransformersPolyglot Mule Transformers
Polyglot Mule Transformers
Sulthony Hartanto
 
MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4
晟 沈
 
Routing
RoutingRouting
Routing
Glenn Guden
 
MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1
晟 沈
 
MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3
晟 沈
 
Java script
Java scriptJava script
Java script
umesh patil
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
Bhavin Shah
 
Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012
daniel plocker
 
Java script
Java scriptJava script
Java script
ITz_1
 
Groovy features
Groovy featuresGroovy features
Groovy features
Ramakrishna kapa
 
MVC for Desktop Application - Part 2
MVC for Desktop Application - Part  2MVC for Desktop Application - Part  2
MVC for Desktop Application - Part 2
晟 沈
 
Java Script
Java ScriptJava Script
Java Script
husbancom
 
Drupalgeddon 2 Null_meet
Drupalgeddon 2 Null_meetDrupalgeddon 2 Null_meet
Drupalgeddon 2 Null_meet
Dhaval Khairnar
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
Edureka!
 
JavaScript: Implementations And Applications
JavaScript: Implementations And ApplicationsJavaScript: Implementations And Applications
JavaScript: Implementations And Applications
Pragya Pai
 
Codeigniter Introduction
Codeigniter IntroductionCodeigniter Introduction
Codeigniter Introduction
Ashfan Ahamed
 
Chapter1 introduction to asp.net
Chapter1  introduction to asp.netChapter1  introduction to asp.net
Chapter1 introduction to asp.net
mentorrbuddy
 
CodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.comCodeIgniter - PHP MVC Framework by silicongulf.com
CodeIgniter - PHP MVC Framework by silicongulf.com
Christopher Cubos
 
MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4
晟 沈
 
MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1
晟 沈
 
MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3
晟 沈
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
Bhavin Shah
 
Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012Client Object Model - SharePoint Extreme 2012
Client Object Model - SharePoint Extreme 2012
daniel plocker
 
Java script
Java scriptJava script
Java script
ITz_1
 
MVC for Desktop Application - Part 2
MVC for Desktop Application - Part  2MVC for Desktop Application - Part  2
MVC for Desktop Application - Part 2
晟 沈
 

Similar to M6 l7-java script-handout (20)

Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
JohnTaieb
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3
Faiz Bashir
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
Bhavsingh Maloth
 
Intro to Javascript and jQuery
Intro to Javascript and jQueryIntro to Javascript and jQuery
Intro to Javascript and jQuery
Shawn Calvert
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
Jaya Kumari
 
Javascript for web Programming creating and embedding with html
Javascript for web Programming creating and embedding with htmlJavascript for web Programming creating and embedding with html
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
William Myers
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
hchen1
 
Frontend Interview Questions PDF By ScholarHat
Frontend Interview Questions PDF By ScholarHatFrontend Interview Questions PDF By ScholarHat
Frontend Interview Questions PDF By ScholarHat
Scholarhat
 
Lezione 03 Introduzione a react
Lezione 03   Introduzione a reactLezione 03   Introduzione a react
Lezione 03 Introduzione a react
University of Catania
 
Java script hello world
Java script hello worldJava script hello world
Java script hello world
sanket kulkarni
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Mahmoud Tolba
 
Introduction to Java script for web .pptx
Introduction to Java script for web .pptxIntroduction to Java script for web .pptx
Introduction to Java script for web .pptx
FahimMousa
 
Making Of PHP Based Web Application
Making Of PHP Based Web ApplicationMaking Of PHP Based Web Application
Making Of PHP Based Web Application
Sachin Walvekar
 
Reactjs Basics
Reactjs BasicsReactjs Basics
Reactjs Basics
Hamid Ghorbani
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
Abhishek Kesharwani
 
J Query
J QueryJ Query
J Query
ravinxg
 
Learn react by Etietop Demas
Learn react by Etietop DemasLearn react by Etietop Demas
Learn react by Etietop Demas
Etietop Demas
 
Frontend Developer Roadmap PDF By Scholarhat
Frontend Developer Roadmap PDF By ScholarhatFrontend Developer Roadmap PDF By Scholarhat
Frontend Developer Roadmap PDF By Scholarhat
Scholarhat
 
Front End Development | Introduction
Front End Development | IntroductionFront End Development | Introduction
Front End Development | Introduction
JohnTaieb
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3
Faiz Bashir
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
Bhavsingh Maloth
 
Intro to Javascript and jQuery
Intro to Javascript and jQueryIntro to Javascript and jQuery
Intro to Javascript and jQuery
Shawn Calvert
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
Jaya Kumari
 
Javascript for web Programming creating and embedding with html
Javascript for web Programming creating and embedding with htmlJavascript for web Programming creating and embedding with html
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
hchen1
 
Frontend Interview Questions PDF By ScholarHat
Frontend Interview Questions PDF By ScholarHatFrontend Interview Questions PDF By ScholarHat
Frontend Interview Questions PDF By ScholarHat
Scholarhat
 
Introduction to Java script for web .pptx
Introduction to Java script for web .pptxIntroduction to Java script for web .pptx
Introduction to Java script for web .pptx
FahimMousa
 
Making Of PHP Based Web Application
Making Of PHP Based Web ApplicationMaking Of PHP Based Web Application
Making Of PHP Based Web Application
Sachin Walvekar
 
Learn react by Etietop Demas
Learn react by Etietop DemasLearn react by Etietop Demas
Learn react by Etietop Demas
Etietop Demas
 
Frontend Developer Roadmap PDF By Scholarhat
Frontend Developer Roadmap PDF By ScholarhatFrontend Developer Roadmap PDF By Scholarhat
Frontend Developer Roadmap PDF By Scholarhat
Scholarhat
 
Ad

M6 l7-java script-handout

  • 1. Web Application Architectures Module 6: Presentation/User Interface Lecture 7: JavaScript & JQuery c 2011-13 G.L. Heileman Module 6, Lecture 7 1 / 9
  • 2. JavaScript JavaScript is a lightweight, interpreted programming language that was designed to be embedded within, and provide scripting capabilities to, any application. A scripting language is used to write “scripts” that are distinct from the core code of an application. Scripts are often written in a language that is different from that of the core application, and they are typically intended to be created/modified by end users. Client-side JavaScript combines the scripting capabilities of the JavaScript interpreter with the document object model (DOM) defined in a web browser, enabling executable content to be distributed over the web. All major browsers include a JavaScript interpreter (engine). c 2011-13 G.L. Heileman Module 6, Lecture 7 2 / 9
  • 3. JavaScript It is also possible to run JavaScript in other environments. Ex. Node.js is a server-side JavaScript application for developing networking applications. JavaScript is primarily used to write functions that are embedded in or included from HTML pages delivered by a web server, for the purpose of dynamically modifying the HTML elements on client-side pages through the DOM. Because JavaScript code runs locally in the browser, it can quickly respond to user actions, making the web application as a whole more responsive. Ex. JavaScript can be used to update a portion of webpage, or to perform client-side validations, prior to submitting form data to the web application. c 2011-13 G.L. Heileman Module 6, Lecture 7 3 / 9
  • 4. The JavaScript Language The syntax of the JavaScript language is highly influenced by C; however JavaScript is actually a multi-paradigm language, supporting the prototype-based, functional, imperative and scripting approaches to programming. It’s easy to access the JavaScript interpreter in your browser: – Put JavaScript code in an HTML file, enclosed within the <script> tag, and render the file in your browser. – Use the JavaScript console provided as a part of the “developer tools” that come with your browser. c 2011-13 G.L. Heileman Module 6, Lecture 7 4 / 9
  • 5. JavaScript Interpreters Consider the recurrence relation for computing the Fibonacci numbers: F(n) =    0, if n = 0 1, if n = 1 F(n − 1) + F(n − 2), if n > 1 Create a file fib.html, containing the following JavaScript code: <script> document.write("<h2>Table of Fibonacci Numbers</h2>"); for (i=0, j=1, k=0, f=0; i<50; i++, f=j+k, j=k, k=f) { document.write("Fibonacci (" + i + ") = " + f); document.write("<br>"); } </script> To execute this code, in your browser address bar type: file://<path_to_file>/fib.html c 2011-13 G.L. Heileman Module 6, Lecture 7 5 / 9
  • 6. JavaScript and Browser Security Client-side JavaScript opens up the possibility for authors to deliver malicious scripts to the browser. Browsers guard against this using two strategies: – JavaScript code is run in a sandbox that only allows web-related actions to be performed, not general-purpose programming tasks (no writing to disk, creating files, etc.). – JavaScript code is constrained by the same origin policy – scripts from one website do not have access to information such as usernames, passwords, or cookies from other websites. c 2011-13 G.L. Heileman Module 6, Lecture 7 6 / 9
  • 7. JavaScript Libraries Numerous JavaScript libraries, containing pre-written JavaScript code, have been developed for the purpose of making the the development of JavaScript-based web applications easier. The most popular JavaScript library is jQuery, and it is now supported by default in Rails. An entire ecosystem has built up around jQuery, including companion libraries (e.g., jQuery UI) and plug-ins (both official and unofficial). jQuery supports the notion of unobtrusive JavaScript – the separation of behavior from document structure. With unobtrusive JavaScript, you never embed any JavaScript expressions or statements within the body of an HTML document, either as attributes of HTML elements (such as onclick) or in script blocks. c 2011-13 G.L. Heileman Module 6, Lecture 7 7 / 9
  • 8. jQuery The jQuery developers placed a high priority on ensuring that it worked consistently across all major browsers. The focus in jQuery is on retrieving elements from HTML pages, and performing operation on them. Elements are retrieved via selectors, using the same selectors that are in CSS. To collect a group of elements, you pass the selector to the jQuery function as follows: jQuery(<selector>) You will more likely encounter the shortcut version of this function call: $(<selector>) This function returns a JavaScript object containing an array of DOM elements that match the selector. c 2011-13 G.L. Heileman Module 6, Lecture 7 8 / 9
  • 9. jQuery The returned elements are actually “wrapped” with additional functions (methods), and these elements are therefore referred to as the wrapped set. Available methods: api.jquery.com. Ex. $("div.byebye").hide(); This will hide all of the div elements in the document that belong to the class bye-bye. Many of the jQuery methods also return a wrapped set, so it’s common to chain methods in jQuery. Ex. $("div.byebye").hide().addClass("removed"); This will add a new class, called removed, to the hidden div elements. c 2011-13 G.L. Heileman Module 6, Lecture 7 9 / 9