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