SlideShare a Scribd company logo
The Document Object Model
(DOM)
An introduction to the concept
Presented By Syed Moosa kaleem
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
"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.
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
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>
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
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 (20)

PDF
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
PPT
Learn javascript easy steps
prince Loffar
 
PDF
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
PDF
jQuery - Chapter 3 - Effects
WebStackAcademy
 
PDF
HTML5 - An introduction
Eleonora Ciceri
 
PPTX
Lecture 5 javascript
Mujtaba Haider
 
PPTX
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
PDF
Angular - Chapter 5 - Directives
WebStackAcademy
 
PPTX
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ayes Chinmay
 
PDF
jQuery -Chapter 2 - Selectors and Events
WebStackAcademy
 
PPTX
Ajax presentation
Bharat_Kumawat
 
PPTX
Getting Started with jQuery
Akshay Mathur
 
PPTX
Java Script basics and DOM
Sukrit Gupta
 
PPT
Java script
vishal choudhary
 
PPTX
Java script basics
Shrivardhan Limbkar
 
PPT
JavaScript JQUERY AJAX
Makarand Bhatambarekar
 
PPTX
Javascript
Prashant Kumar
 
PDF
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
PPT
Java script -23jan2015
Sasidhar Kothuru
 
PDF
Intro to JavaScript
Jussi Pohjolainen
 
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Learn javascript easy steps
prince Loffar
 
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
jQuery - Chapter 3 - Effects
WebStackAcademy
 
HTML5 - An introduction
Eleonora Ciceri
 
Lecture 5 javascript
Mujtaba Haider
 
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
Angular - Chapter 5 - Directives
WebStackAcademy
 
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Ayes Chinmay
 
jQuery -Chapter 2 - Selectors and Events
WebStackAcademy
 
Ajax presentation
Bharat_Kumawat
 
Getting Started with jQuery
Akshay Mathur
 
Java Script basics and DOM
Sukrit Gupta
 
Java script
vishal choudhary
 
Java script basics
Shrivardhan Limbkar
 
JavaScript JQUERY AJAX
Makarand Bhatambarekar
 
Javascript
Prashant Kumar
 
Unit 4(it workshop)
Dr.Lokesh Gagnani
 
Java script -23jan2015
Sasidhar Kothuru
 
Intro to JavaScript
Jussi Pohjolainen
 

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

PPTX
UNIT 1 (7).pptx
DrDhivyaaCRAssistant
 
PPTX
BITM3730 10-3.pptx
MattMarino13
 
PPTX
BITM3730 10-4.pptx
MattMarino13
 
PPTX
javaScript and jQuery
Mehrab Hossain
 
PDF
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
PPTX
BITM3730Week6.pptx
MattMarino13
 
PPTX
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
PPT
Jquery 1
Manish Kumar Singh
 
PPTX
Web Development Introduction to jQuery
Laurence Svekis ✔
 
PPT
lecture 6 javascript event and event handling.ppt
ULADATZ
 
PPTX
JavaScripts & jQuery
Asanka Indrajith
 
PPTX
J Query The Write Less Do More Javascript Library
rsnarayanan
 
PPTX
Javascript note for engineering notes.pptx
engineeradda55
 
PDF
Lecture 10.pdf
ssuser0890d1
 
PDF
Client sidescripting javascript
Selvin Josy Bai Somu
 
PDF
JavaScript
Bharti Gupta
 
PPT
JavaScript Basics with baby steps
Muhammad khurram khan
 
PPTX
JSON & AJAX.pptx
dyumna2
 
KEY
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
UNIT 1 (7).pptx
DrDhivyaaCRAssistant
 
BITM3730 10-3.pptx
MattMarino13
 
BITM3730 10-4.pptx
MattMarino13
 
javaScript and jQuery
Mehrab Hossain
 
AJS UNIT-1 2021-converted.pdf
SreeVani74
 
BITM3730Week6.pptx
MattMarino13
 
Javascript for web Programming creating and embedding with html
E.M.G.yadava womens college
 
Web Development Introduction to jQuery
Laurence Svekis ✔
 
lecture 6 javascript event and event handling.ppt
ULADATZ
 
JavaScripts & jQuery
Asanka Indrajith
 
J Query The Write Less Do More Javascript Library
rsnarayanan
 
Javascript note for engineering notes.pptx
engineeradda55
 
Lecture 10.pdf
ssuser0890d1
 
Client sidescripting javascript
Selvin Josy Bai Somu
 
JavaScript
Bharti Gupta
 
JavaScript Basics with baby steps
Muhammad khurram khan
 
JSON & AJAX.pptx
dyumna2
 
JavaScript Neednt Hurt - JavaBin talk
Thomas Kjeldahl Nilsson
 
Ad

Recently uploaded (20)

PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Ad

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
  • 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.
  • 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>
  • 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