SlideShare a Scribd company logo
1 of 40
The Document Object Model
(DOM)
An introduction to the concept
Presented By Syed Moosa kaleem
"The Document Object Model is
a platform- and language-neutral interface
that will allow programs and scripts
to dynamically access and update
the content, structure and style of documents.
The document can be further processed
and the results of that processing
can be incorporated
back into the presented page."
ā€”World Wide Web Consortium (W3C)
"A tree of nodes"
ā€¢ A document is represented as a tree of
nodes of various types.
ā€¢ Many nodes have 'child' nodes (and any child has a direct
"parent").
ā€¢ A child is a node. Any node may have "children."
ā€¢ The "sibling of a node is a node that is on the same level or line,
neither above it or below it.
An idea to understand
<div>
<p> This is a <em>new</em> paragraph in an HTML document.
</p>
</div>
The <p>is a child of the <div>.
The <em> is a child of the <p>.
Introduction to JavaScript
Programming
What is JavaScript?
ā€¢ Interpreted programming or scripting language from Netscape.
ā€¢ Easier to code than the compiled languages like C and C++.
ā€¢ Lightweight and most commonly used script in web pages.
ā€¢ Allow client-side user to interact and create dynamic pages.
ā€¢ Cross-platform and object-oriented scripting language.
ā€¢ Most popular programming language in the world.
ā€¢ High level, dynamic and untyped programming language.
ā€¢ Standardized in the ECMAScript language specification.
ā€¢ Used for shorter programs
ā€¢ Takes longer time to process than compiled languages.
JavaScript Variables
ā€¢ There are two types of variables: local and global. You declare local variables
using the var keyword and global variables without using the var keyword.
ā€¢ With the var keyword the variable is considered local because it cannot be
accessed anywhere outside the scope of the place you declare it.
ā€¢ For example, declaring a local variable inside a function, it cannot be accessed
outside of that function, which makes it local to that function.
ā€¢ Declaring the same variable without the var keyword, it is accessible
throughout the entire script, not only within that function. Which makes it
global within script tag.
ā€¢ Declaring a local variable
var num = 10;
ā€¢ To access the value of the num variable at another point in the script, you
simply reference the variable by name Ex:
document.write("The value of num is: "+ num);
JavaScript Operators
ā€¢ You need operators when performing any operation in the
JavaScript language.
ā€¢ Operations include addition, subtraction, comparison, and so
on. There are four types of operators in the JavaScript
language.
ā€¢ Arithmetic.
ā€¢ Assignment .
ā€¢ Comparison .
ā€¢ Logical
Arrays
ā€¢ Arrays are similar to variables, but they can hold multiple values.
ā€¢ There is no limit to the amount or type of data that you can store in a
JavaScript array.
ā€¢ We can access any value of any item in an array at any time after
declaring it.
ā€¢ Arrays can hold any data type in the JavaScript language.
ā€¢ Arrays can store only similar data in any one array.
ā€¢ Storing similar values in an array
ā€¢ var colors new Array("orange", ' 'blue", " red", "brown");
var shapes new Array("circle", "square", "triangle", " pentagon");
ā€¢ Accessing values in an array is easy, but there is a catch. Arrays always start
with an ID of O, rather than 1.
ā€¢ To access an array item you must use its ID, which refers to the item's
position in the array.
Functions
ā€¢ Functions are containers for script that is only to be executed by an
event or a call to the function.
ā€¢ Functions do not execute when the browser initially loads and
executes the script that is included in a web page.
ā€¢ The purpose of a function is to contain script that has a task so that
you then have the ability to execute that script and run that task at
any time.
ā€¢ Structuring a simple function
var num 10;
function changeVariableValue() {
num -11;
changeVariableValue();
document.write("num is: "+ num); }
Using JavaScript in HTML code
<!DOCTYPE html>
<html>
<body>
<p>A typical arithmetic operation takes two numbers and produces a new number.</p>
<p id="demo"></p>
<script>
var x = 100 + 50;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
Now itā€™s time for jQuery
introduction
What is jQuery?
ā€¢ JavaScript library.
ā€¢ Cross-browser support.
ā€¢ Aimed for client-side scripting.
ā€¢ Released in 2006.
ā€¢ Most popular JS library today
ā€¢ FOSS (Free and Open Source Software).
ā€¢ www.jquery.com
jQuery features
ā€¢ DOM elements: select, modify .
ā€¢ Events.
ā€¢ CSS handling
ā€¢ Flashy effects
ā€¢ Ajax
ā€¢ Very easy to use!
Examples
ā€¢ $(ā€œdiv ") Selects all divs
ā€¢ $(".myClass") Selects all items with myClass class
ā€¢ $("#myld") Selects all items with myld id (should be just one!)
ā€¢ $("div.myClass") Selects all divs with myClass class.
ā€¢ $("div.myClass").append(ā€œ<p>Text appended</p>ā€); Appends
paragraph
ā€¢ $("#myld").css({font-size:15px});
Test page
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>
jQuery Event Methods
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
</body>
</html>
jQuery - AJAX Introduction
ā€¢ AJAX = Asynchronous JavaScript and XML.
ā€¢ AJAX is the art of exchanging data with a server, and updating parts of
a web page - without reloading the whole page.
ā€¢ Examples of applications using AJAX: Gmail, Google Maps, Youtube,
and Facebook tabs.
ā€¢ jQuery provides several methods for AJAX functionality.
ā€¢ With the jQuery AJAX methods, you can request text, HTML, XML, or
JSON from a remote server using both HTTP Get and HTTP Post - And
you can load the external data directly into the selected HTML
elements of your web page!
jQuery Ajax Example
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("demo_test.txt");
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
jQuery Effects - Animation
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({left: '250px'});
});
});
</script>
</head>
<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position
property of the element to relative, fixed, or absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div>
</body>
</html>
AJAX Introduction
ā€¢ AJAX = Asynchronous JavaScript And XML.
ā€¢ AJAX is not a programming language.
ā€¢ AJAX is a developer's dream, because you can:
ā€¢ Update a web page without reloading the page
ā€¢ Request data from a server - after the page has loaded
ā€¢ Receive data from a server - after the page has loaded
ā€¢ Send data to a server - in the background
Real-Life Examples of AJAX
ā€¢ Google Maps
- http://maps.google.com/
ā€¢ Google Suggest
http :/ /www.google.com/
ā€¢ Gmail
- http://gmail.com/
AJAX Basics
ā€¢ AJAX uses XMLHttpRequest
ā€¢ JavaScript communicates directly with the server, through
the JavaScript XMLHttpRequest object .
ā€¢ With an XMLHTTPRequest, a web page can make a
request to, and get a response from a web server - without
reloading the page.
Ajax Example
<!DOCTYPE html>
<html>
<body>
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Request data</button>
<p id="demo"></p>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "demo_get.asp", true);
xhttp.send();
} </script>
</body>
</html>
Cross Domain Ajax
ā€¢ A common problem for developers is a browser to refuse access to a
remote resource. Usually, this happens when you execute AJAX cross
domain request using jQuery or plain XMLHttpRequest.
Introduction to JSON
ā€¢ What is JSON?
ā€¢ JSON stands for JavaScript Object Notation. JSON objects are used for
transferring data between server and client.
ā€¢ JSON is a subset of JavaScript. ( ECMA-262 ).
ā€¢ Language Independent, means it can work well with most of the modern
programming language
ā€¢ Text-based, human readable data exchange format
ā€¢ Light-weight. Easier to get and load the requested data quickly.
ā€¢ Easy to parse.
ā€¢ JSON is very stable
ā€¢ official Internet media type for JSON is application/json.
ā€¢ JSON Is Not XML.
ā€¢ JSON is a simple, common representation of data.
JSON Syntax
ā€¢ { "name":"John" }
ā€¢ JSON Uses JavaScript Syntax
ā€¢ Because JSON syntax is derived from JavaScript object notation, very
little extra software is needed to work with JSON within JavaScript.
ā€¢ var person = { "name":"John", "age":31, "city":"New York" };
JSON Data Types
ā€¢ In JSON, values must be one of the following data types:
ā€¢ a string
ā€¢ a number
ā€¢ an object (JSON object)
ā€¢ an array
ā€¢ a boolean
ā€¢ null
ā€¢ JSON Strings
ā€¢ { "name":"John" }
ā€¢ JSON Numbers
ā€¢ { "age":30 }
ā€¢ JSON Objects
ā€¢ {
"employee":{ "name":"John", "age":30, "city":"New York" }
}
ā€¢ JSON Arrays
ā€¢ {
"employees":[ "John", "Anna", "Peter" ]
}
ā€¢ JSON Booleans
ā€¢ { "sale":true }
ā€¢ Accessing Object Values
ā€¢ myObj = { "name":"John", "age":30, "car":null };
x = myObj.name;
JSON.parse()
ā€¢ A common use of JSON is to exchange data to/from a web server.
ā€¢ When receiving data from a web server, the data is always a string.
ā€¢ Parse the data with JSON.parse(), and the data becomes a JavaScript object.
ā€¢ Example
ā€¢ <!DOCTYPE html>
ā€¢ <html>
ā€¢ <body>
ā€¢ <h2>Create Object from JSON String</h2>
ā€¢ <p id="demo"></p>
ā€¢ <script>
ā€¢ var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}');
ā€¢ document.getElementById("demo").innerHTML = obj.name + ", " + obj.age;
ā€¢ </script>
ā€¢ </body>
ā€¢ </html>
JSON.stringify()
ā€¢ A common use of JSON is to exchange data to/from a web server.
ā€¢ When sending data to a web server, the data has to be a string.
ā€¢ Convert a JavaScript object into a string with JSON.stringify().
ā€¢ <!DOCTYPE html>
ā€¢ <html>
ā€¢ <body>
ā€¢ <h2>Create JSON string from a JavaScript object.</h2>
ā€¢ <p id="demo"></p>
ā€¢ <script>
ā€¢ var obj = { "name":"John", "age":30, "city":"New York"};
ā€¢ var myJSON = JSON.stringify(obj);
ā€¢ document.getElementById("demo").innerHTML = myJSON;
ā€¢ </script>
ā€¢ </body>
ā€¢ </html>
Thank You!
For more info you can visit my YouTube Channel
EPICOP
https://www.youtube.com/channel/UCILksVrhIlS-pxcFqvFHM4A

More Related Content

What's hot

HTML5 - An introduction
HTML5 - An introductionHTML5 - An introduction
HTML5 - An introduction
Eleonora Ciceri
Ā 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
Ā 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
Sukrit Gupta
Ā 

What's hot (20)

Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
Ā 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
Ā 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
Ā 
jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects  jQuery - Chapter 3 - Effects
jQuery - Chapter 3 - Effects
Ā 
HTML5 - An introduction
HTML5 - An introductionHTML5 - An introduction
HTML5 - An introduction
Ā 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
Ā 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Ā 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
Ā 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ā 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
Ā 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
Ā 
Getting Started with jQuery
Getting Started with jQueryGetting Started with jQuery
Getting Started with jQuery
Ā 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
Ā 
Java script
Java scriptJava script
Java script
Ā 
Java script basics
Java script basicsJava script basics
Java script basics
Ā 
JavaScript JQUERY AJAX
JavaScript JQUERY AJAXJavaScript JQUERY AJAX
JavaScript JQUERY AJAX
Ā 
Javascript
JavascriptJavascript
Javascript
Ā 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
Ā 
Java script -23jan2015
Java script -23jan2015Java script -23jan2015
Java script -23jan2015
Ā 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
Ā 

Similar to An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON

Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
rumsan
Ā 
Java script202
Java script202Java script202
Java script202
Wasiq Zia
Ā 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
Asanka Indrajith
Ā 
Java script.pptx v
Java script.pptx                                     vJava script.pptx                                     v
Java script.pptx v
22x026
Ā 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
Ā 
JS basics
JS basicsJS basics
JS basics
Mohd Saeed
Ā 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Mahmoud Tolba
Ā 

Similar to An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON (20)

Java script
Java scriptJava script
Java script
Ā 
Java Script - A New Look
Java Script - A New LookJava Script - A New Look
Java Script - A New Look
Ā 
J query resh
J query reshJ query resh
J query resh
Ā 
Java script202
Java script202Java script202
Java script202
Ā 
Jqueryppt (1)
Jqueryppt (1)Jqueryppt (1)
Jqueryppt (1)
Ā 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Ā 
AJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdfAJS UNIT-1 2021-converted.pdf
AJS UNIT-1 2021-converted.pdf
Ā 
WTA-MODULE-4.pptx
WTA-MODULE-4.pptxWTA-MODULE-4.pptx
WTA-MODULE-4.pptx
Ā 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
Ā 
Event Programming JavaScript
Event Programming JavaScriptEvent Programming JavaScript
Event Programming JavaScript
Ā 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
Ā 
Java script.pptx v
Java script.pptx                                     vJava script.pptx                                     v
Java script.pptx v
Ā 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
Ā 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
Ā 
Java script
Java scriptJava script
Java script
Ā 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
Ā 
JS basics
JS basicsJS basics
JS basics
Ā 
Java script
Java scriptJava script
Java script
Ā 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
Ā 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
Ā 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
Ā 

Recently uploaded (20)

šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Ā 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Ā 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
Ā 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Ā 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Ā 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Ā 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Ā 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Ā 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Ā 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
Ā 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Ā 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
Ā 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Ā 

An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON

  • 1. The Document Object Model (DOM) An introduction to the concept Presented By Syed Moosa kaleem
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. "The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results of that processing can be incorporated back into the presented page." ā€”World Wide Web Consortium (W3C)
  • 7. "A tree of nodes" ā€¢ A document is represented as a tree of nodes of various types. ā€¢ Many nodes have 'child' nodes (and any child has a direct "parent"). ā€¢ A child is a node. Any node may have "children." ā€¢ The "sibling of a node is a node that is on the same level or line, neither above it or below it.
  • 8. An idea to understand <div> <p> This is a <em>new</em> paragraph in an HTML document. </p> </div> The <p>is a child of the <div>. The <em> is a child of the <p>.
  • 10. What is JavaScript? ā€¢ Interpreted programming or scripting language from Netscape. ā€¢ Easier to code than the compiled languages like C and C++. ā€¢ Lightweight and most commonly used script in web pages. ā€¢ Allow client-side user to interact and create dynamic pages. ā€¢ Cross-platform and object-oriented scripting language. ā€¢ Most popular programming language in the world. ā€¢ High level, dynamic and untyped programming language. ā€¢ Standardized in the ECMAScript language specification. ā€¢ Used for shorter programs ā€¢ Takes longer time to process than compiled languages.
  • 11. JavaScript Variables ā€¢ There are two types of variables: local and global. You declare local variables using the var keyword and global variables without using the var keyword. ā€¢ With the var keyword the variable is considered local because it cannot be accessed anywhere outside the scope of the place you declare it. ā€¢ For example, declaring a local variable inside a function, it cannot be accessed outside of that function, which makes it local to that function. ā€¢ Declaring the same variable without the var keyword, it is accessible throughout the entire script, not only within that function. Which makes it global within script tag. ā€¢ Declaring a local variable var num = 10; ā€¢ To access the value of the num variable at another point in the script, you simply reference the variable by name Ex: document.write("The value of num is: "+ num);
  • 12. JavaScript Operators ā€¢ You need operators when performing any operation in the JavaScript language. ā€¢ Operations include addition, subtraction, comparison, and so on. There are four types of operators in the JavaScript language. ā€¢ Arithmetic. ā€¢ Assignment . ā€¢ Comparison . ā€¢ Logical
  • 13. Arrays ā€¢ Arrays are similar to variables, but they can hold multiple values. ā€¢ There is no limit to the amount or type of data that you can store in a JavaScript array. ā€¢ We can access any value of any item in an array at any time after declaring it. ā€¢ Arrays can hold any data type in the JavaScript language. ā€¢ Arrays can store only similar data in any one array. ā€¢ Storing similar values in an array ā€¢ var colors new Array("orange", ' 'blue", " red", "brown"); var shapes new Array("circle", "square", "triangle", " pentagon"); ā€¢ Accessing values in an array is easy, but there is a catch. Arrays always start with an ID of O, rather than 1. ā€¢ To access an array item you must use its ID, which refers to the item's position in the array.
  • 14. Functions ā€¢ Functions are containers for script that is only to be executed by an event or a call to the function. ā€¢ Functions do not execute when the browser initially loads and executes the script that is included in a web page. ā€¢ The purpose of a function is to contain script that has a task so that you then have the ability to execute that script and run that task at any time. ā€¢ Structuring a simple function var num 10; function changeVariableValue() { num -11; changeVariableValue(); document.write("num is: "+ num); }
  • 15. Using JavaScript in HTML code <!DOCTYPE html> <html> <body> <p>A typical arithmetic operation takes two numbers and produces a new number.</p> <p id="demo"></p> <script> var x = 100 + 50; document.getElementById("demo").innerHTML = x; </script> </body> </html>
  • 16. Now itā€™s time for jQuery introduction
  • 17. What is jQuery? ā€¢ JavaScript library. ā€¢ Cross-browser support. ā€¢ Aimed for client-side scripting. ā€¢ Released in 2006. ā€¢ Most popular JS library today ā€¢ FOSS (Free and Open Source Software). ā€¢ www.jquery.com
  • 18. jQuery features ā€¢ DOM elements: select, modify . ā€¢ Events. ā€¢ CSS handling ā€¢ Flashy effects ā€¢ Ajax ā€¢ Very easy to use!
  • 19. Examples ā€¢ $(ā€œdiv ") Selects all divs ā€¢ $(".myClass") Selects all items with myClass class ā€¢ $("#myld") Selects all items with myld id (should be just one!) ā€¢ $("div.myClass") Selects all divs with myClass class. ā€¢ $("div.myClass").append(ā€œ<p>Text appended</p>ā€); Appends paragraph ā€¢ $("#myld").css({font-size:15px});
  • 20. Test page <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> <body> <p>If you click on me, I will disappear.</p> <p>Click me away!</p> <p>Click me too!</p> </body> </html>
  • 21. jQuery Event Methods <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); </script> </head> <body> <p>If you click on me, I will disappear.</p> <p>Click me away!</p> <p>Click me too!</p> </body> </html>
  • 22. jQuery - AJAX Introduction ā€¢ AJAX = Asynchronous JavaScript and XML. ā€¢ AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page. ā€¢ Examples of applications using AJAX: Gmail, Google Maps, Youtube, and Facebook tabs. ā€¢ jQuery provides several methods for AJAX functionality. ā€¢ With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!
  • 23. jQuery Ajax Example <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("demo_test.txt"); }); }); </script> </head> <body> <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div> <button>Get External Content</button> </body> </html>
  • 24. jQuery Effects - Animation <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("div").animate({left: '250px'}); }); }); </script> </head> <body> <button>Start Animation</button> <p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p> <div style="background:#98bf21;height:100px;width:100px;position:absolute;"></div> </body> </html>
  • 25. AJAX Introduction ā€¢ AJAX = Asynchronous JavaScript And XML. ā€¢ AJAX is not a programming language. ā€¢ AJAX is a developer's dream, because you can: ā€¢ Update a web page without reloading the page ā€¢ Request data from a server - after the page has loaded ā€¢ Receive data from a server - after the page has loaded ā€¢ Send data to a server - in the background
  • 26. Real-Life Examples of AJAX ā€¢ Google Maps - http://maps.google.com/ ā€¢ Google Suggest http :/ /www.google.com/ ā€¢ Gmail - http://gmail.com/
  • 27. AJAX Basics ā€¢ AJAX uses XMLHttpRequest ā€¢ JavaScript communicates directly with the server, through the JavaScript XMLHttpRequest object . ā€¢ With an XMLHTTPRequest, a web page can make a request to, and get a response from a web server - without reloading the page.
  • 28.
  • 29.
  • 30. Ajax Example <!DOCTYPE html> <html> <body> <h1>The XMLHttpRequest Object</h1> <button type="button" onclick="loadDoc()">Request data</button> <p id="demo"></p> <script> function loadDoc() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("GET", "demo_get.asp", true); xhttp.send(); } </script> </body> </html>
  • 31.
  • 32.
  • 33. Cross Domain Ajax ā€¢ A common problem for developers is a browser to refuse access to a remote resource. Usually, this happens when you execute AJAX cross domain request using jQuery or plain XMLHttpRequest.
  • 34. Introduction to JSON ā€¢ What is JSON? ā€¢ JSON stands for JavaScript Object Notation. JSON objects are used for transferring data between server and client. ā€¢ JSON is a subset of JavaScript. ( ECMA-262 ). ā€¢ Language Independent, means it can work well with most of the modern programming language ā€¢ Text-based, human readable data exchange format ā€¢ Light-weight. Easier to get and load the requested data quickly. ā€¢ Easy to parse. ā€¢ JSON is very stable ā€¢ official Internet media type for JSON is application/json. ā€¢ JSON Is Not XML. ā€¢ JSON is a simple, common representation of data.
  • 35. JSON Syntax ā€¢ { "name":"John" } ā€¢ JSON Uses JavaScript Syntax ā€¢ Because JSON syntax is derived from JavaScript object notation, very little extra software is needed to work with JSON within JavaScript. ā€¢ var person = { "name":"John", "age":31, "city":"New York" };
  • 36. JSON Data Types ā€¢ In JSON, values must be one of the following data types: ā€¢ a string ā€¢ a number ā€¢ an object (JSON object) ā€¢ an array ā€¢ a boolean ā€¢ null
  • 37. ā€¢ JSON Strings ā€¢ { "name":"John" } ā€¢ JSON Numbers ā€¢ { "age":30 } ā€¢ JSON Objects ā€¢ { "employee":{ "name":"John", "age":30, "city":"New York" } } ā€¢ JSON Arrays ā€¢ { "employees":[ "John", "Anna", "Peter" ] } ā€¢ JSON Booleans ā€¢ { "sale":true } ā€¢ Accessing Object Values ā€¢ myObj = { "name":"John", "age":30, "car":null }; x = myObj.name;
  • 38. JSON.parse() ā€¢ A common use of JSON is to exchange data to/from a web server. ā€¢ When receiving data from a web server, the data is always a string. ā€¢ Parse the data with JSON.parse(), and the data becomes a JavaScript object. ā€¢ Example ā€¢ <!DOCTYPE html> ā€¢ <html> ā€¢ <body> ā€¢ <h2>Create Object from JSON String</h2> ā€¢ <p id="demo"></p> ā€¢ <script> ā€¢ var obj = JSON.parse('{ "name":"John", "age":30, "city":"New York"}'); ā€¢ document.getElementById("demo").innerHTML = obj.name + ", " + obj.age; ā€¢ </script> ā€¢ </body> ā€¢ </html>
  • 39. JSON.stringify() ā€¢ A common use of JSON is to exchange data to/from a web server. ā€¢ When sending data to a web server, the data has to be a string. ā€¢ Convert a JavaScript object into a string with JSON.stringify(). ā€¢ <!DOCTYPE html> ā€¢ <html> ā€¢ <body> ā€¢ <h2>Create JSON string from a JavaScript object.</h2> ā€¢ <p id="demo"></p> ā€¢ <script> ā€¢ var obj = { "name":"John", "age":30, "city":"New York"}; ā€¢ var myJSON = JSON.stringify(obj); ā€¢ document.getElementById("demo").innerHTML = myJSON; ā€¢ </script> ā€¢ </body> ā€¢ </html>
  • 40. Thank You! For more info you can visit my YouTube Channel EPICOP https://www.youtube.com/channel/UCILksVrhIlS-pxcFqvFHM4A