SlideShare a Scribd company logo
DESIGNVELOPER
JavaScript Introduction
• JavaScript is the most popular programming
language in the world.
• JavaScript is the language for the web
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Variables
• Declaring:
– var x=10
– var y
• Global variable:
Declaring : x=0;
• Local variable
Declaring : var x=0
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Objects
• Almost "everything" in JavaScript can be
objects. Strings, Dates, Arrays, Functions....
• There are many different ways to create new
JavaScript objects, and you can also add new
properties and methods to already existing
objects.
• Example:
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Creating JavaScript Objects
• Methods defined internally
function Apple (type) {
this.type = type;
this.color = "red";
this.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
}
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Creating JavaScript Objects
• Methods added to the prototype
function Apple (type)
{
this.type = type;
this.color = "red";
}
Apple.prototype.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Creating JavaScript Objects
• To instantiate an object using the
Apple constructor function, set some
properties and call methods you can do the
following:
• var apple = new Apple('macintosh');
apple.color = "reddish";
alert(apple.getInfo());
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Using object literals
• Literals are shorter way to define objects and
arrays in JavaScript. To create an empty object
using you can do:
var o = {};
instead of the "normal" way:
var o = new Object();
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Using object literals
• var apple = {
type: "macintosh",
color: "red",
getInfo: function () {
return this.color + ' ' + this.type + ' apple';
}
}
In this case you don't need to (and cannot) create an instance of
the class, it already exists. So you simply start using this instance.
apple.color = "reddish";
alert(apple.getInfo());
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Singleton using a function
• You can use a function to define a singleton
object. Here's the syntax:
var apple = new function() {
this.type = "macintosh";
this.color = "red";
this.getInfo = function () {
return this.color + ' ' + this.type + ' apple';
};
}
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Singleton using a function
• So you see that this is very similar to 1.
discussed above, but the way to use the
object is exactly like in 2.
apple.color = "reddish";
alert(apple.getInfo());
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Functions
• JavaScript Numbers
• JavaScript Strings
• JavaScript Dates
• JavaScript Arrays
• JavaScript Booleans
• JavaScript Maths
• JavaScript Operators
• JavaScript If...Else Statements
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Switch Statement
• JavaScript For Loop
• JavaScript While Loop
• JavaScript Break and Continue
• JavaScript Errors - Throw and Try to Catch
• JavaScript Form Validation
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript HTML DOM
• With the object model, JavaScript gets all the power it
needs to create dynamic HTML:
• JavaScript can change all the HTML elements in the page
• JavaScript can change all the HTML attributes in the page
• JavaScript can change all the CSS styles in the page
• JavaScript can remove existing HTML elements and
attributes
• JavaScript can add new HTML elements and attributes
• JavaScript can react to all existing HTML events in the page
• JavaScript can create new HTML events in the page
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript - HTML DOM Methods
• HTML DOM methods are actions you can
perform (on HTML Elements)
• HTML DOM properties are values (of HTML
Elements) that you can set or change
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript HTML DOM Document
• In the HTML DOM object model, the
document object represents your web page.
• The document object is the owner of all other
objects in your web page.
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript HTML DOM - Changing HTML
• JavaScript HTML DOM - Changing CSS
– <p id="p2">Hello World!</p>
<script>
document.getElementById("p2").style.color="blue";
</script>
<p>The paragraph above was changed by a script.</p>
JavaScript HTML DOM Event
• JavaScript HTML DOM Events
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript HTML DOM Elements
(Nodes)
• To add a new element to the HTML DOM, you must create
the element (element node) first, and then append it to an
existing element.
• <div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
<script>
var para=document.createElement("p");
var node=document.createTextNode("This is new.");
para.appendChild(node);
var element=document.getElementById("div1");
element.appendChild(para);
</script>
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
HTML DOM Node List Length
• The length property defines the number of nodes
in a node-list.
• You can loop through a node-list by using the
length property:
• x=document.getElementsByTagName("p");
for (i=0;i<x.length;i++)
{
document.write(x[i].innerHTML);
document.write("<br />");
}
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
The Browser Object Model
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
The Browser Object Model
• The window object is supported by all browsers. It
represent the browser's window.
• For Internet Explorer, Chrome, Firefox, Opera, and Safari:
– window.innerHeight - the inner height of the browser window
– window.innerWidth - the inner width of the browser window
• For Internet Explorer 8, 7, 6, 5:
– document.documentElement.clientHeight
– document.documentElement.clientWidth
– or
– document.body.clientHeight
– document.body.clientWidth
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
The Browser Object Model
• Some other methods:
– window.open() - open a new window
– window.close() - close the current window
– window.moveTo() -move the current window
– window.resizeTo() -resize the current window
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Window Screen
– screen.availWidth - available screen width
– screen.availHeight - available screen height
• JavaScript Window Location
– location.hostname returns the domain name of the
web host
– location.pathname returns the path and filename of
the current page
– location.port returns the port of the web host (80 or
443)
– location.protocol returns the web protocol used
(http:// or https://)
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Window History
– history.back() - same as clicking back in the
browser
– history.forward() - same as clicking forward in the
browser
• JavaScript Window Navigator
– The window.navigator object contains information
about the visitor's browser.
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
• JavaScript Popup Boxes
– Alert Box
– Confirm Box
– Prompt Box
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Timing Events
• setInterval() - executes a function, over and
over again, at specified time intervals
• setTimeout() - executes a function, once, after
waiting a specified number of milliseconds
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Cookies
• Create a Cookie with JavaScript
– document.cookie="username=John Doe";
• You can also add an expiry date (in UTC or
GMT time). By default, the cookie is deleted
when the browser is closed:
– document.cookie="username=John Doe;
expires=Thu, 18 Dec 2013 12:00:00 GMT; path=/";
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript Cookies
• Delete a Cookie with JavaScript
– document.cookie = "username=; expires=Thu, 01
Jan 1970 00:00:00 GMT";
• Read a Cookie with JavaScript
– var x = document.cookie;
document.cookie will return all cookies in one string
much like: cookie1=value; cookie2=value;
cookie3=value;
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
JavaScript RegExp Object
• JavaScript RegExp Object
• A regular expression is an object that
describes a pattern of characters.
• When you search in a text, you can use a
pattern to describe what you are searching for.
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Java Script Ajax
• AJAX is the art of exchanging data with a
server, and updating parts of a web page -
without reloading the whole page.
• How AJAX Works
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City
Website: http://designveloper.com
Address: 250/6 Bau Cat, Ward 11, Tan Binh
District, HCM City

More Related Content

What's hot (6)

PPTX
Rapi::Blog talk - TPC 2017
Henry Van Styn
 
PPTX
JS digest. April 2018
ElifTech
 
PPTX
Untangling spring week5
Derek Jacoby
 
PPTX
Untangling spring week4
Derek Jacoby
 
PPTX
RapidApp - YAPC::NA 2014
Henry Van Styn
 
PPTX
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Mike Schinkel
 
Rapi::Blog talk - TPC 2017
Henry Van Styn
 
JS digest. April 2018
ElifTech
 
Untangling spring week5
Derek Jacoby
 
Untangling spring week4
Derek Jacoby
 
RapidApp - YAPC::NA 2014
Henry Van Styn
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Mike Schinkel
 

Viewers also liked (6)

PDF
The Role Of Java Script
Christian Heilmann
 
PPTX
Présentation JavaScript
tarkan_
 
PDF
Basics of JavaScript
Bala Narayanan
 
PPTX
JavaScript Presentation Frameworks and Libraries
Oleksii Prohonnyi
 
PDF
Introduction to JavaScript
Bryan Basham
 
PPTX
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)
Suthep Sangvirotjanaphat
 
The Role Of Java Script
Christian Heilmann
 
Présentation JavaScript
tarkan_
 
Basics of JavaScript
Bala Narayanan
 
JavaScript Presentation Frameworks and Libraries
Oleksii Prohonnyi
 
Introduction to JavaScript
Bryan Basham
 
Mudularity and Unit Testing in TypeScript (for ng-bkk #3)
Suthep Sangvirotjanaphat
 
Ad

Similar to JavaScript Introduction (20)

PPTX
Jquery
Designveloper
 
PPTX
Cordova training : Day 4 - Advanced Javascript
Binu Paul
 
PPT
WEB DESIGNING VNSGU UNIT 4 JAVASCRIPT OBJECTS
divyapatel123440
 
PPTX
12. session 12 java script objects
Phúc Đỗ
 
PPTX
JavaScript
Vidyut Singhania
 
PDF
Java script
Yoga Raja
 
PPTX
javaScript and jQuery
Mehrab Hossain
 
PDF
Java script
Ramesh Kumar
 
PPTX
BITM3730 10-4.pptx
MattMarino13
 
PPTX
BITM3730 10-3.pptx
MattMarino13
 
PPTX
Jquery fundamentals
Salvatore Fazio
 
PDF
L7. Object in JS, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
PPTX
Html5 and web technology update
Doug Domeny
 
PPT
Applied component i unit 2
Pramod Redekar
 
PPTX
Advanced JavaScript
Mahmoud Tolba
 
PDF
Prototype 150 Api
guest54a182
 
PPTX
Javascript Objects and Functions
Gitanjali wagh
 
PPTX
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
Shaymaa
 
PPTX
Javascript Best Practices and Intro to Titanium
Techday7
 
PPTX
Object Oriented Javascript part2
Usman Mehmood
 
Cordova training : Day 4 - Advanced Javascript
Binu Paul
 
WEB DESIGNING VNSGU UNIT 4 JAVASCRIPT OBJECTS
divyapatel123440
 
12. session 12 java script objects
Phúc Đỗ
 
JavaScript
Vidyut Singhania
 
Java script
Yoga Raja
 
javaScript and jQuery
Mehrab Hossain
 
Java script
Ramesh Kumar
 
BITM3730 10-4.pptx
MattMarino13
 
BITM3730 10-3.pptx
MattMarino13
 
Jquery fundamentals
Salvatore Fazio
 
L7. Object in JS, CSE 202, BN11.pdf JavaScript
SauravBarua11
 
Html5 and web technology update
Doug Domeny
 
Applied component i unit 2
Pramod Redekar
 
Advanced JavaScript
Mahmoud Tolba
 
Prototype 150 Api
guest54a182
 
Javascript Objects and Functions
Gitanjali wagh
 
HTML5: The Future of Web Development with IE9, IE10 and Windows 8
Shaymaa
 
Javascript Best Practices and Intro to Titanium
Techday7
 
Object Oriented Javascript part2
Usman Mehmood
 
Ad

More from Designveloper (20)

PDF
Let us take care of your brand image
Designveloper
 
PDF
5 java script frameworks to watch in 2017
Designveloper
 
PDF
Happy international women's day!
Designveloper
 
PDF
Typing racer game - a nice break from work
Designveloper
 
PDF
Should we work remotely?
Designveloper
 
PDF
Meet song nhi your virtual financial assistance
Designveloper
 
PDF
Why pair programming is a good idea
Designveloper
 
PDF
5 worst mistakes of diy websites
Designveloper
 
PDF
Basic glossary of web design terms for non designers (part 2)
Designveloper
 
PDF
Single page web application development using meteor js
Designveloper
 
PDF
Multiplayer game with unity3 d and meteor
Designveloper
 
PDF
Awesome free resources for learning javascript
Designveloper
 
PDF
What is the best java script frameworks to learn?
Designveloper
 
PDF
Travelling forms a young man
Designveloper
 
PDF
5 compelling reasons your website should be responsive
Designveloper
 
PDF
Reactive programming with tracker
Designveloper
 
PDF
Benefits of using single page websites
Designveloper
 
PDF
What is the best programming language for beginner?
Designveloper
 
PDF
No sql injection in meteor.js application
Designveloper
 
PDF
How to deploy and scale your meteor apps
Designveloper
 
Let us take care of your brand image
Designveloper
 
5 java script frameworks to watch in 2017
Designveloper
 
Happy international women's day!
Designveloper
 
Typing racer game - a nice break from work
Designveloper
 
Should we work remotely?
Designveloper
 
Meet song nhi your virtual financial assistance
Designveloper
 
Why pair programming is a good idea
Designveloper
 
5 worst mistakes of diy websites
Designveloper
 
Basic glossary of web design terms for non designers (part 2)
Designveloper
 
Single page web application development using meteor js
Designveloper
 
Multiplayer game with unity3 d and meteor
Designveloper
 
Awesome free resources for learning javascript
Designveloper
 
What is the best java script frameworks to learn?
Designveloper
 
Travelling forms a young man
Designveloper
 
5 compelling reasons your website should be responsive
Designveloper
 
Reactive programming with tracker
Designveloper
 
Benefits of using single page websites
Designveloper
 
What is the best programming language for beginner?
Designveloper
 
No sql injection in meteor.js application
Designveloper
 
How to deploy and scale your meteor apps
Designveloper
 

Recently uploaded (20)

PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Digital Circuits, important subject in CS
contactparinay1
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 

JavaScript Introduction

  • 1. DESIGNVELOPER JavaScript Introduction • JavaScript is the most popular programming language in the world. • JavaScript is the language for the web Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 2. JavaScript Variables • Declaring: – var x=10 – var y • Global variable: Declaring : x=0; • Local variable Declaring : var x=0 Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 3. JavaScript Objects • Almost "everything" in JavaScript can be objects. Strings, Dates, Arrays, Functions.... • There are many different ways to create new JavaScript objects, and you can also add new properties and methods to already existing objects. • Example: Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 4. Creating JavaScript Objects • Methods defined internally function Apple (type) { this.type = type; this.color = "red"; this.getInfo = function() { return this.color + ' ' + this.type + ' apple'; }; } Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 5. Creating JavaScript Objects • Methods added to the prototype function Apple (type) { this.type = type; this.color = "red"; } Apple.prototype.getInfo = function() { return this.color + ' ' + this.type + ' apple'; }; Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 6. Creating JavaScript Objects • To instantiate an object using the Apple constructor function, set some properties and call methods you can do the following: • var apple = new Apple('macintosh'); apple.color = "reddish"; alert(apple.getInfo()); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 7. Using object literals • Literals are shorter way to define objects and arrays in JavaScript. To create an empty object using you can do: var o = {}; instead of the "normal" way: var o = new Object(); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 8. Using object literals • var apple = { type: "macintosh", color: "red", getInfo: function () { return this.color + ' ' + this.type + ' apple'; } } In this case you don't need to (and cannot) create an instance of the class, it already exists. So you simply start using this instance. apple.color = "reddish"; alert(apple.getInfo()); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 9. Singleton using a function • You can use a function to define a singleton object. Here's the syntax: var apple = new function() { this.type = "macintosh"; this.color = "red"; this.getInfo = function () { return this.color + ' ' + this.type + ' apple'; }; } Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 10. Singleton using a function • So you see that this is very similar to 1. discussed above, but the way to use the object is exactly like in 2. apple.color = "reddish"; alert(apple.getInfo()); Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 11. • JavaScript Functions • JavaScript Numbers • JavaScript Strings • JavaScript Dates • JavaScript Arrays • JavaScript Booleans • JavaScript Maths • JavaScript Operators • JavaScript If...Else Statements Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 12. • JavaScript Switch Statement • JavaScript For Loop • JavaScript While Loop • JavaScript Break and Continue • JavaScript Errors - Throw and Try to Catch • JavaScript Form Validation Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 13. JavaScript HTML DOM • With the object model, JavaScript gets all the power it needs to create dynamic HTML: • JavaScript can change all the HTML elements in the page • JavaScript can change all the HTML attributes in the page • JavaScript can change all the CSS styles in the page • JavaScript can remove existing HTML elements and attributes • JavaScript can add new HTML elements and attributes • JavaScript can react to all existing HTML events in the page • JavaScript can create new HTML events in the page Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 14. JavaScript - HTML DOM Methods • HTML DOM methods are actions you can perform (on HTML Elements) • HTML DOM properties are values (of HTML Elements) that you can set or change Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 15. JavaScript HTML DOM Document • In the HTML DOM object model, the document object represents your web page. • The document object is the owner of all other objects in your web page. Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 16. • JavaScript HTML DOM - Changing HTML • JavaScript HTML DOM - Changing CSS – <p id="p2">Hello World!</p> <script> document.getElementById("p2").style.color="blue"; </script> <p>The paragraph above was changed by a script.</p> JavaScript HTML DOM Event • JavaScript HTML DOM Events Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 17. JavaScript HTML DOM Elements (Nodes) • To add a new element to the HTML DOM, you must create the element (element node) first, and then append it to an existing element. • <div id="div1"> <p id="p1">This is a paragraph.</p> <p id="p2">This is another paragraph.</p> </div> <script> var para=document.createElement("p"); var node=document.createTextNode("This is new."); para.appendChild(node); var element=document.getElementById("div1"); element.appendChild(para); </script> Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 18. HTML DOM Node List Length • The length property defines the number of nodes in a node-list. • You can loop through a node-list by using the length property: • x=document.getElementsByTagName("p"); for (i=0;i<x.length;i++) { document.write(x[i].innerHTML); document.write("<br />"); } Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 19. The Browser Object Model Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 20. The Browser Object Model • The window object is supported by all browsers. It represent the browser's window. • For Internet Explorer, Chrome, Firefox, Opera, and Safari: – window.innerHeight - the inner height of the browser window – window.innerWidth - the inner width of the browser window • For Internet Explorer 8, 7, 6, 5: – document.documentElement.clientHeight – document.documentElement.clientWidth – or – document.body.clientHeight – document.body.clientWidth Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 21. The Browser Object Model • Some other methods: – window.open() - open a new window – window.close() - close the current window – window.moveTo() -move the current window – window.resizeTo() -resize the current window Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 22. • JavaScript Window Screen – screen.availWidth - available screen width – screen.availHeight - available screen height • JavaScript Window Location – location.hostname returns the domain name of the web host – location.pathname returns the path and filename of the current page – location.port returns the port of the web host (80 or 443) – location.protocol returns the web protocol used (http:// or https://) Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 23. • JavaScript Window History – history.back() - same as clicking back in the browser – history.forward() - same as clicking forward in the browser • JavaScript Window Navigator – The window.navigator object contains information about the visitor's browser. Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 24. • JavaScript Popup Boxes – Alert Box – Confirm Box – Prompt Box Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 25. JavaScript Timing Events • setInterval() - executes a function, over and over again, at specified time intervals • setTimeout() - executes a function, once, after waiting a specified number of milliseconds Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 26. JavaScript Cookies • Create a Cookie with JavaScript – document.cookie="username=John Doe"; • You can also add an expiry date (in UTC or GMT time). By default, the cookie is deleted when the browser is closed: – document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 GMT; path=/"; Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 27. JavaScript Cookies • Delete a Cookie with JavaScript – document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 GMT"; • Read a Cookie with JavaScript – var x = document.cookie; document.cookie will return all cookies in one string much like: cookie1=value; cookie2=value; cookie3=value; Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 28. JavaScript RegExp Object • JavaScript RegExp Object • A regular expression is an object that describes a pattern of characters. • When you search in a text, you can use a pattern to describe what you are searching for. Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City
  • 29. Java Script Ajax • AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page. • How AJAX Works Website: http://designveloper.com Address: 250/6 Bau Cat, Ward 11, Tan Binh District, HCM City