SlideShare a Scribd company logo
Javascript
1Computer Network & Web Tech (SET, JU)
Introduction
• 3 Components in design of a Web page
 HTML  content
 CSS  appearance
 Javascript  dynamic behaviour
<!DOCTYPE html>
<html>
<body>
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
</html> js1
2Computer Network & Web Tech (SET, JU)
Introduction
• All major web browsers contain JavaScript interpreters, which process
the commands written in JavaScript
 IE9 prevents scripts from running by default
 Need to change browser settings to enable scripting
 Firefox, Chrome, Opera, Safari (including on the iPhone) and the
Android browser - JS enabled by default
 Google – Settings > Privacy -> Content Settings
• Setting to check error while running program
 Error console for displaying errors
3Computer Network & Web Tech (SET, JU)
Embedding Javascript
 Use <script> tag, in <head> section of HTML documents usually
 Indicates to the browser that the text that follows is part of a script
 <type> attribute indicates the programming language – default JS
 Either contains scripting statements, or it points to an external script file
through the src attribute
<script type=“text/javascript">
<!- hide this stuff from old browsers
document.writeln(“<h1> Welcome to JS programming </h1>”)
// - -> end hiding
</script>
Js2
Prior to html5
4Computer Network & Web Tech (SET, JU)
Output
 Writing into an HTML element, using innerHTML
 Writing into the HTML output using document.write()
 Writing into an alert box, using window.alert()
 Writing into the browser console, using console.log()
5Computer Network & Web Tech (SET, JU)
Changing HTML Content
 Common uses for JavaScript are image manipulation, form validation,
dynamic changes of content
 Within body, have an element to invoke the function, and another with
id “demo” whose content will be modified
<button type="button" onclick="myFunction()">Click Me!</button>
<p id="demo">This is a demonstration.</p> js3
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello
JavaScript!";
}
</script>
6Computer Network & Web Tech (SET, JU)
Changing HTML Attributes
 Example: Change an image by changing src attribute
<button onclick = "document.getElementById('myImage').src
='bulbon.gif'">Turn on the light</button>
<img id="myImage" src="pic_bulboff.gif" style="width:100px">
<button onclick="document.getElementById('myImage').src
='bulboff.gif'">Turn off the light</button>
js5
7Computer Network & Web Tech (SET, JU)
Changing HTML Styles
 For changing style
• Note: Javascript accepts both single and double quotes
<script>
function myFunction() {
document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "red"; }
</script>
js4
8Computer Network & Web Tech (SET, JU)
Hide and Show Elements
 Hiding HTML elements can be done by changing the display style:
 Showing hidden HTML elements can also be done by changing the
display style
document.getElementById("demo").style.display = "none";
js6
document.getElementById("demo").style.display = “block";
9Computer Network & Web Tech (SET, JU)
Javascript Syntax
 Statements with
 Values (literals and variables)
 Operators
 Expressions
 Keywords
 Comments
10Computer Network & Web Tech (SET, JU)
Operators
 Arithmetic
a + b, a – b, a % b, a * b, a / b
 Rule of precedence as in algebra
 Multiplication, Division, Remainder  same level L to R
 Addition & Subtraction  same level L to R
 a + b + c + d / 4
 (a + b + c + d)/ 4
 Good practice to use parenthesis to make expressions clear
11Computer Network & Web Tech (SET, JU)
Operators
 Bitwise : &, |, ~, ^, <<, >>
 Relational : > , <, >=, <=
 Equality: ==, !=
 Logical: &&, ||
 Assignment: =
 Unary post/pre increment or decrement operators ++, --
Precedence
•Multiplicative
•Additive
•Relational
•Equality
•Assignment
12Computer Network & Web Tech (SET, JU)
Variables
 All variables declared using keyword ‘var’ (keyword  reserved)
 Location in memory where value can be stored for later use
 Has name, type, value
<html>
<head>
<script>
var name; //string entered by user
name=window.prompt(“Enter your name”);
document.writeln(“<h1> Hello,” + name +
“; welcome ! </h1>”) ;
</script>
</head>
<body>
<p > Click to Refresh </p>
</body>
</html>
js7
13Computer Network & Web Tech (SET, JU)
Windows Prompt
– Taking User Input
 If ‘Cancel’ clicked, value “null” submitted (absence of value)
 Else, name entered is returned by windows.prompt (as string)
and gets assigned to name variable
name = windows.prompt (“Enter your name “);
 Assignment statement  right side evaluated first
 HTML loaded after dialog boxes dismissed
14Computer Network & Web Tech (SET, JU)
Windows Alert
 Predefined dialog box called ‘alert’ - used for popups
<html>
<head>
<script>
Window.alert(“Welcome to n Javascript n programming”);
</script>
</head>
<body>
<p > Click Refresh to run script again </p>
</body>
</html>
js9
15Computer Network & Web Tech (SET, JU)
Variables
 Good practice to declare variables using <var>, not necessary
 Value at time of declaration or later
<head>
<script>
var sec_per_min=60;
var min_per_hr=60;
var hr_per_day=8;
var secs_per_day;
secs_per_day= sec_per_min * min_per_hr * hr_per_day;
</script>
</head>
<body>
<script>
document.write(“A student studies”)
document.write(secs_per_day + “ seconds per day </b>”);
</script>
</body> Js8,js10
16Computer Network & Web Tech (SET, JU)
Variables - Loose typing
 Variables can be assigned to data type without declaring
 Javascript converts data type
 + concatenation with string, addition with integer
“My age is “ + 21  converts data to string
 String is a group of characters
17Computer Network & Web Tech (SET, JU)
Naming Variables
 Case sensitive -> str, Str, STR different
 Combination of characters – letters, digit, underscore, $
 Does not begin with digit, cannot be a kerword
 Valid - $val, _val, m_val, val7
 Invalid - 7val
Good programming practices
• Use meaningful names – itemPrice
• Comment purpose of variable at time of declaration
// single-line comment
/* Multiple line
Comment */ 18Computer Network & Web Tech (SET, JU)
Branching
 If, if .. else …
 Nested If… else if .. else if ..
 Indentation good programming practice – increases readability
 But note that else with previous if – better to use brackets
If (x > 5)
If (y>5)
document. write (“x> 5 and y>5”)
else
document.write (“x<5”)  wrong
19Computer Network & Web Tech (SET, JU)
Conditional If
var name;
var now=new date(); //current date and time
var hr = now.getHours(); // current hour 0 - 23
If (hr <12 )
document. write (“Good morning”);
else {
hr=hr-12;
if (hr < 6)
document.write (“Good afternoon”) ;
Else
document.write(“Good evening”); } 20Computer Network & Web Tech (SET, JU)
Looping
 While  repetition on entry
var cnt=0;
while (cnt<5) {
….
cnt ++; }
 For  repetition on entry
for (cnt=1; cnt<=7; ++cnt) cnt++, cnt+=1
for (loop=0; loop < width; loop++) {
a_line = a_line + "x";
}
var password="passport";
var answer;
while (answer != password) {
answer = prompt("What's the word?","");
}
document.write(“<h1>That’s correct</h1>”);
21Computer Network & Web Tech (SET, JU)
Labelled Break & Continue
<script>
Stop: { //labelled block
for (var row=1; row <=10; ++row) {
for (var col =1; col <=5; ++col) {
if (row==5)
break stop;
document. write (“*”); } //end for
document.writeln(“<br/>”); } //end for
document.writeln(“This line should not print”);
} // end block labelled stop
document.writeln(“End of script”);
</script>
22Computer Network & Web Tech (SET, JU)
Javascript Functions
• Divide and conquer using functions
• Help in modularity, reusability
• Avoid repeating pieces of code
• Function invoked using name and arguments
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
• Calling function asks called function to perform task and return task
after result is done
var x = myFunction(4, 3); // Function is called, return value
23Computer Network & Web Tech (SET, JU)
Javascript Built-in Functions
• Functions belong to Javascript objects called methods
• Rich collection for string, date-time, array manipulations, calculations
• Use such built-in functions - less development time, less chance of error
function maximum(x, y, z) {
return Math.max(x, Math.max(y, z); }
<script>
var input1 = windows.prompt(“Enter number 1”)
var input2 = windows.prompt(“Enter number 2”)
var input3 = windows.prompt(“Enter number 3”)
var value1 = parseFloat(input1);
var value2 = parseFloat(input2);
var value3 = parseFloat(input3);
var maxval = maximum(value1, value2, value3);
</script> 24Computer Network & Web Tech (SET, JU)
Javascript Objects
var person = {
firstName:“Akash",
lastName:“Agarwal",
age:50,
eyeColor:"black"
};
• Properties: name-value pairs
• All instances of person object have same properties, but different values
for these properties
• Property can be accessed as objectName.propertyName or
objectName["propertyName"]
person.lastName;
person["lastName"];
25Computer Network & Web Tech (SET, JU)
Object Methods
var person = {
firstName:“Akash",
lastName:“Agarwal",
age:50,
eyeColor:"black“
fullName function() {return this.firstName + " " + this.lastName;}
};
• Methods are actions that can be performed on objects
• All methods of person object have same methods, but the methods are
performed at different times
• Methods can be accessed as objectName.methodName()
person.fullName;
26Computer Network & Web Tech (SET, JU)
String Object
var txt = “testing**"; txt = “’testing’**";
var sln = txt.length;
Series of characters / special characters *, _ , () etc.
• Property - length
• Escape characters used with quotes
var x = "John";
var y = new String("John");
(x==y)  true as value same
(x===y)  false as types different
Also string objects cannot be compared
27Computer Network & Web Tech (SET, JU)
String Methods
charAt(index)  returns string containing character at index, or empty string if NA
charCodeAt(index)  returns unicode value of character at position or NaN if NA
If s= “ZEBRA” s. charAt(0)  “Z” ; s.charCodeAt(0) 90
If s=“TeStInG”, s1.LowerCase  “testing” ;
s1.UpperCase  “TESTING”
• fromCharCode(value1, value2)  Converts a list of unicode values to
corresponding character string
string.fromCharCode(87, 79, 82, 68)  “WORD”
• s1.concat(s2)  concatenates s1 with s2, returns new string
28Computer Network & Web Tech (SET, JU)
String Search Methods
ltrl=“abcdefghidef”
ltrl.indexOf(“def”) 3
ltrl.LastindexOf(“def”) 10
ltrl.LastindexOf(“def”,7) 10
ltrl.LastindexOf(“def”,10) 3
ltrl.searchf(“def”) 3
• Search() and indexOf() functions similar, differences are as follows:
• search() method cannot take a second start position argument.
• The search() method can take much more powerful search values (regular
expressions)
29Computer Network & Web Tech (SET, JU)
String Extraction Methods
slice(start, end)
var str = "Apple, Banana, Kiwi“
str.slice(7,13)  Banana str.slice(-12, -6)  Banana
Omit the second parameter, the method will slice out the rest of the string
substring(start, end)
substring() is similar to slice(), except cannot receive negative inputs
substr(start, length)
substring() is similar to slice(), except 2nd parameter specifies length
30Computer Network & Web Tech (SET, JU)
Replacing String Content
replace() method replaces a specified value with another value in a string
var str = "Apple, Banana, Kiwi“;
var n =str.replace( “Banana “, “Orange”) ;
 replace() does not change the string it is called on, returns a new string
 replaces only first occurrence until /g option specified
n = str.replace(/an/g, “st");
 Case sensitive method
 To replace case insensitive, use a regular expression with an /i flag
n = str.replace(/AN/i, “st");
31Computer Network & Web Tech (SET, JU)
Math Object
Math.round(4.5)  5 Math.round(4.4) 4
Math.ceil(4.2)  5 Math.ceil(-4.2)  -4 Math.floor(x)
Math.abs(-2.7)  2.7
Math.pow(8, 2)  64 (x to the power y)
Math.exp(x)  (e to the power x) exp(1.0)  2.718
Math.log(x)  (natural log base e of x) log(2.718) 1.0
max(2.3, 12.7)  12.7
min(-2.3, -12.7)  -12.7
sin(x), cos(x), tan(x), sqrt(x)
CONSTANTS
Math.PI  22/7, Math.SQRT2 1.414, Math.E  2.718, Math.LN20.693
32Computer Network & Web Tech (SET, JU)
Date Object
getDate() Get the day as a number (1-31)
getUTCDate() Get the day as in Universal Time Zone
getDay() Get the weekday as a number (0-6)
getFullYear() Get the four digit year (yyyy)
getHours() Get the hour (0-23)
getMilliseconds() Get the milliseconds (0-999)
getMinutes() Get the minutes (0-59)
getMonth() Get the month (0-11)
getSeconds() Get the seconds (0-59)
getTime() Get the time (milliseconds since January 1, 1970)
setDate(val) Set the day as a number (1-31), can add number
d.setDate(d.getDate() + 50);
setFullYear(y,m,d) m,d optional, if not mentioned default from current date
33Computer Network & Web Tech (SET, JU)
Working with Date Object
Parsing Dates
Date.parse() returns the number of milliseconds between the date and January 1,
1970 from a valid string
<script>
var msec = Date.parse("March 17, 2015");
document.getElementById("demo").innerHTML = msec;
</script>
Comparing Dates
today = new Date();
someday = new Date();
someday.setFullYear(2100, 0, 14);
if (someday > today) { text = "Today is before January 14, 2100.";}
else { text = "Today is after January 14, 2100."; }
34Computer Network & Web Tech (SET, JU)
Number Object
var x = 9.656;
x.toString() Returns string “9.656” in place of number
x.fixed(2) Returns specified number of decimals i.e. 9.66
x.toPrecision(2) Returns 9.7
x.valueOf Returns numeric value from object or other data type
var b= new boolean(true)
b.toString  “true”
b.valueOf ()  1
35Computer Network & Web Tech (SET, JU)
Converting Variables to Numbers
number() Returns a number, converted from its argument
parseInt() Parses a string and returns a whole number*
parseFloat() Parses a string and returns a number*
*Spaces are allowed. Only the first number is returned
x = true;
Number(x); // returns 1
parseInt("10.33"); // returns 10
parseFloat("10.33"); // returns 10.33
x = "10 20"
Number(x); // returns NaN
36Computer Network & Web Tech (SET, JU)
Arrays
 Data structure consisting of related data items
 Group of memory locations that have same name, usually same data type
 Used to allocate memory, instantiate object
var c=new Array(12)  elements not initialized, undefined
Initialization
for var i=0; i < c.length, ++i)
c[i] = i  length of array c
// iterate through elements of array using for .. In
for (var i in theArray)
total +=theArray[i]
Definition & initialization together
var n = new Array (10, 20, 30, 40, 50); 37Computer Network & Web Tech (SET, JU)
Declaring & Allocating Arrays
 Arrays use space in memory
 ‘new’ dynamic memory location operator
 Referred using []
 Number within square bracket indicates size during declaration
 Called subscript or index
 Arr_name[0] –refers to first element arr_name[6]  7th element
 c.length  length of array c
 Arrays used when you want the element names to be numbers
 If a=6, b=5, c[a+b]+=2  Increment c[11] by 2
38Computer Network & Web Tech (SET, JU)
Pass By Reference
 Pass by value  when arguments passed, copy of arguments value is
made and passed to calling function
(numbers, strings, boolean values)
 Pass by reference  caller gives called function direct access to caller’s
data and also allows to modify it
 Address of memory location where data resides is passed
(objects, arrays passed by reference)
39Computer Network & Web Tech (SET, JU)
Linear Search in Arrays
 Var a = [10, 9, 1, 3, 5, 7]
function linearSearch(a, key)
{
for (var n=0; n<a.length, ++n)
if ( a[n] == key)
return n;
return -1;
}
40Computer Network & Web Tech (SET, JU)
Sorting Arrays
 Var a = [10, 9, 1, 3, 5, 7]
function compareInt(val1, val2)
{return parseInt(val1) – parseInt(val(2))
Complete sort function using this…
41Computer Network & Web Tech (SET, JU)
Split & Join Functions
 Split function to split string into array elements
vary parts = "cpu,disk,memory,monitor,keyboard,mouse";
var parts_array = parts.split(",");
for (loop=0; loop < parts_array.length; loop++)
{
document.writeln("A computer has " + parts_array[loop] + ".<br>");
}
Join method of array to join string, may use different delimiter
document.getElementById(“output”).value = parts_array.join(“n”);
42Computer Network & Web Tech (SET, JU)
Window Object
 Used for manipulating browser window
window.open(URL, name, options)  creates new window with URL and name
as mentioned, visible features set by options
window.prompt(prompt)  displays user box asking foruser input
windows.close  close current window & delete object from memory
windows.focus  set focus to that window
windows.blur  take away focus
windows.document  property  document object representing the
visible document in the window
windows.closed  property boolean value, true if window closed
43Computer Network & Web Tech (SET, JU)
Document Object
 Used for manipulating the document visible in browser window
write(string)  write string to HTML doc as HTML code
writeln(string)  write as above, add a line feed
Each such “write” resumes writing where stopped before.
For writeln, next write begins on new line
<script>
document.write(“<h1 style =”color : red ” >”);  modify to display in red
document.write(“Welcome to programming in Javascript “ </h1> “);
</script>
44Computer Network & Web Tech (SET, JU)
Document Object
 One can write multiple lines using single sentence
writeln(“ Welcome to <br/> programming <br/> in Javascript”)
 Use “+” operator to split statement over multiple line, but rendered as
single line
<script>
document.write(“<h1 style =”color : red ” >”);  modify to display in red
document.write(“Welcome to programming in” +
“Javascript” </h1>”);
</script>
45Computer Network & Web Tech (SET, JU)
Document Object Model
 When browser loads a page, creates a DOM for page
 Gives access to all elements in page
 Using JS, elements in page can be created, modified, removed
Modelling a Document: DOM Nodes & Trees
Every element in HTML page is modelled by web browser as DOM node
Nodes in a document together make up a tree
– Describes relationship among nodes
− Nodes related among each other using parent-child relationship
− HTML element inside another – container element parent, contained
element child
− Nodes may have multiple children, but only single parent
46Computer Network & Web Tech (SET, JU)
Document Object Model
47Computer Network & Web Tech (SET, JU)
Demonstration of TREE
<html>
<head>
<title> DOM Tree Demo </title>
</head>
<body>
<h1> HTML Page </h1>
<p> Here is the list: </p>
<ul >
<li>One</li>
<li>Two</li>
</ul>
</body>
</html>
-#document
- html
- head
-title
#text
- body
- h1
#text
-#text
-p
#text
-#text
- ul
-li
#text
-li
#text
48Computer Network & Web Tech (SET, JU)
Document Object Model
 Standard object model and programming interface for HTML
 HTML DOM defines:
 HTML elements as objects
 Properties of all HTML elements
 Methods to access all HTML elements
 Events for all HTML elements
<script>
document.getElementById(“Hello”).innerHTML=“Hello”;
</script>
</html>
Methods
document.getElementByTagName(name)  find elements by tagname
document.getElementByClassName(name)  nonunique, array 49Computer Network & Web Tech (SET, JU)
Document Object Model
 The HTML DOM is a standard for how to get, change, add, or delete
HTML elements (nodes) dynamically
 Also used to
 Change attributes , CSS styles in the page
 React to all existing HTML events in the page
 Create new events in the page
Adding & Deleting Elements
document.createElement(name)
document.removeChild(name)
document.appendChild(name)
document.replaceChild(new, old)
Changing attributes & styles
element.innerHTML = new html content
element.attribute= new value;
element.setAttribute(attribute,value)
element.style.proerty= new style
50Computer Network & Web Tech (SET, JU)
Traversing & Modifying DOM Tree
 Create New Node
<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);  add text to p
var element = document.getElementById("div1");
element.appendChild(para);  add as last node of div1
</script>
var element = document.getElementById("div1");
var child = document.getElementById("p1");
element.insertBefore(para, child);  add before p1 51Computer Network & Web Tech (SET, JU)
Traversing & Modifying DOM Tree
 Remove Existing Node
<script>
var parent = document.getElementById("div1");
var child = document.getElementById("p1");
parent.removeChild(child);
</script>
 Replace Child
<script>
var para = document.createElement("p");
var node = document.createTextNode("This is new.");
para.appendChild(node);
var parent = document.getElementById("div1");
var child = document.getElementById("p1");
parent.replaceChild(para, child);
</script>
52Computer Network & Web Tech (SET, JU)
Document Object Properties
document.cookie
 Returns document’s cookie
(Piece of data in user’s computer maintaining information about
client during & in between sessions)
 Contains name-value pairs separated by semicolon
if (document.cookie)
{
var myCookie=unescape(document.Cookie);
var cookieTokens =myCookie.split(“;“)
name = cookieTokens[i]
}
53Computer Network & Web Tech (SET, JU)
Document Object Properties
document.anchors Returns all <a> elements that have a name attribut
document.URI Returns URI of document
document.domain Returns domain name of document server
document.lastModified Returns the date and time the document was updated
document.links Returns all elements that have a href attribute
document.title Returns title of document
54Computer Network & Web Tech (SET, JU)

More Related Content

PDF
Practica n° 7
PDF
Java script programms
PDF
Node.js in action
PPT
JavaTalks: OOD principles
KEY
CouchDB on Android
PDF
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
PDF
OpenERP e l'arte della gestione aziendale con Python
ODP
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...
Practica n° 7
Java script programms
Node.js in action
JavaTalks: OOD principles
CouchDB on Android
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
OpenERP e l'arte della gestione aziendale con Python
Nagios Conference 2014 - Troy Lea - JavaScript and jQuery - Nagios XI Tips, T...

What's hot (18)

PDF
Spock and Geb in Action
PPTX
Rails, Postgres, Angular, and Bootstrap: The Power Stack
PDF
My app is secure... I think
PDF
Rapid web development, the right way.
PDF
Backbone Basics with Examples
PPTX
Python Code Camp for Professionals 4/4
PPTX
Python Code Camp for Professionals 3/4
PDF
Ten useful JavaScript tips & best practices
PDF
YouDrup_in_Drupal
PDF
Alfredo-PUMEX
PDF
Python Templating Engine - Intro to Jinja
PDF
Rails' Next Top Model
PDF
RicoLiveGrid
PDF
밑바닥부터 시작하는 의료 AI
ODP
My app is secure... I think
PPTX
Blockly
PDF
td_mxc_rubyrails_shin
KEY
Html5 For Jjugccc2009fall
Spock and Geb in Action
Rails, Postgres, Angular, and Bootstrap: The Power Stack
My app is secure... I think
Rapid web development, the right way.
Backbone Basics with Examples
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 3/4
Ten useful JavaScript tips & best practices
YouDrup_in_Drupal
Alfredo-PUMEX
Python Templating Engine - Intro to Jinja
Rails' Next Top Model
RicoLiveGrid
밑바닥부터 시작하는 의료 AI
My app is secure... I think
Blockly
td_mxc_rubyrails_shin
Html5 For Jjugccc2009fall
Ad

Similar to Javascript 1 (20)

PDF
Ajax Performance Tuning and Best Practices
PPTX
Powershell Tech Ed2009
PDF
HTML5 New and Improved
PDF
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
PPTX
Basics of Java Script (JS)
PPSX
Introduction to Html5
PPTX
01 Introduction - JavaScript Development
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PDF
JavaScript Refactoring
KEY
前端概述
PPTX
Protractor framework – how to make stable e2e tests for Angular applications
PPS
PPTX
Intro to Javascript
PPTX
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
PPTX
Internet Based Programming -3-JAVASCRIPT
PDF
Play 2.0
PPTX
Implementation of GUI Framework part3
PPT
eXo SEA - JavaScript Introduction Training
PPT
Javascript1
PPT
Java script
Ajax Performance Tuning and Best Practices
Powershell Tech Ed2009
HTML5 New and Improved
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Basics of Java Script (JS)
Introduction to Html5
01 Introduction - JavaScript Development
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript Refactoring
前端概述
Protractor framework – how to make stable e2e tests for Angular applications
Intro to Javascript
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Internet Based Programming -3-JAVASCRIPT
Play 2.0
Implementation of GUI Framework part3
eXo SEA - JavaScript Introduction Training
Javascript1
Java script
Ad

More from pavishkumarsingh (19)

PPTX
PPTX
PPTX
Javascript 2
PPTX
PPTX
PPTX
PPTX
PPTX
PPTX
DOC
Final action script
PDF
Multimedia system
PDF
Visual basic
DOC
Human - compuTer interaction
PDF
Multimedia system(OPEN DOCUMENT ARCHITECTURE AND INTERCHANGING FORMAT)
PDF
Authoring metaphors
DOC
Final action script for visual basic
DOC
Cognitive aspects in human computer interaction
DOC
list script and flowchart
DOCX
Networks
Javascript 2
Final action script
Multimedia system
Visual basic
Human - compuTer interaction
Multimedia system(OPEN DOCUMENT ARCHITECTURE AND INTERCHANGING FORMAT)
Authoring metaphors
Final action script for visual basic
Cognitive aspects in human computer interaction
list script and flowchart
Networks

Recently uploaded (20)

PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
composite construction of structures.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Welding lecture in detail for understanding
PDF
PPT on Performance Review to get promotions
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Operating System & Kernel Study Guide-1 - converted.pdf
composite construction of structures.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Sustainable Sites - Green Building Construction
UNIT-1 - COAL BASED THERMAL POWER PLANTS
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
bas. eng. economics group 4 presentation 1.pptx
Welding lecture in detail for understanding
PPT on Performance Review to get promotions
Automation-in-Manufacturing-Chapter-Introduction.pdf
OOP with Java - Java Introduction (Basics)
CH1 Production IntroductoryConcepts.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

Javascript 1

  • 1. Javascript 1Computer Network & Web Tech (SET, JU)
  • 2. Introduction • 3 Components in design of a Web page  HTML  content  CSS  appearance  Javascript  dynamic behaviour <!DOCTYPE html> <html> <body> <h1>My First JavaScript</h1> <button type="button" onclick="document.getElementById('demo').innerHTML = Date()"> Click me to display Date and Time.</button> <p id="demo"></p> </body> </html> js1 2Computer Network & Web Tech (SET, JU)
  • 3. Introduction • All major web browsers contain JavaScript interpreters, which process the commands written in JavaScript  IE9 prevents scripts from running by default  Need to change browser settings to enable scripting  Firefox, Chrome, Opera, Safari (including on the iPhone) and the Android browser - JS enabled by default  Google – Settings > Privacy -> Content Settings • Setting to check error while running program  Error console for displaying errors 3Computer Network & Web Tech (SET, JU)
  • 4. Embedding Javascript  Use <script> tag, in <head> section of HTML documents usually  Indicates to the browser that the text that follows is part of a script  <type> attribute indicates the programming language – default JS  Either contains scripting statements, or it points to an external script file through the src attribute <script type=“text/javascript"> <!- hide this stuff from old browsers document.writeln(“<h1> Welcome to JS programming </h1>”) // - -> end hiding </script> Js2 Prior to html5 4Computer Network & Web Tech (SET, JU)
  • 5. Output  Writing into an HTML element, using innerHTML  Writing into the HTML output using document.write()  Writing into an alert box, using window.alert()  Writing into the browser console, using console.log() 5Computer Network & Web Tech (SET, JU)
  • 6. Changing HTML Content  Common uses for JavaScript are image manipulation, form validation, dynamic changes of content  Within body, have an element to invoke the function, and another with id “demo” whose content will be modified <button type="button" onclick="myFunction()">Click Me!</button> <p id="demo">This is a demonstration.</p> js3 <script> function myFunction() { document.getElementById("demo").innerHTML = "Hello JavaScript!"; } </script> 6Computer Network & Web Tech (SET, JU)
  • 7. Changing HTML Attributes  Example: Change an image by changing src attribute <button onclick = "document.getElementById('myImage').src ='bulbon.gif'">Turn on the light</button> <img id="myImage" src="pic_bulboff.gif" style="width:100px"> <button onclick="document.getElementById('myImage').src ='bulboff.gif'">Turn off the light</button> js5 7Computer Network & Web Tech (SET, JU)
  • 8. Changing HTML Styles  For changing style • Note: Javascript accepts both single and double quotes <script> function myFunction() { document.getElementById("demo").style.fontSize = "25px"; document.getElementById("demo").style.color = "red"; } </script> js4 8Computer Network & Web Tech (SET, JU)
  • 9. Hide and Show Elements  Hiding HTML elements can be done by changing the display style:  Showing hidden HTML elements can also be done by changing the display style document.getElementById("demo").style.display = "none"; js6 document.getElementById("demo").style.display = “block"; 9Computer Network & Web Tech (SET, JU)
  • 10. Javascript Syntax  Statements with  Values (literals and variables)  Operators  Expressions  Keywords  Comments 10Computer Network & Web Tech (SET, JU)
  • 11. Operators  Arithmetic a + b, a – b, a % b, a * b, a / b  Rule of precedence as in algebra  Multiplication, Division, Remainder  same level L to R  Addition & Subtraction  same level L to R  a + b + c + d / 4  (a + b + c + d)/ 4  Good practice to use parenthesis to make expressions clear 11Computer Network & Web Tech (SET, JU)
  • 12. Operators  Bitwise : &, |, ~, ^, <<, >>  Relational : > , <, >=, <=  Equality: ==, !=  Logical: &&, ||  Assignment: =  Unary post/pre increment or decrement operators ++, -- Precedence •Multiplicative •Additive •Relational •Equality •Assignment 12Computer Network & Web Tech (SET, JU)
  • 13. Variables  All variables declared using keyword ‘var’ (keyword  reserved)  Location in memory where value can be stored for later use  Has name, type, value <html> <head> <script> var name; //string entered by user name=window.prompt(“Enter your name”); document.writeln(“<h1> Hello,” + name + “; welcome ! </h1>”) ; </script> </head> <body> <p > Click to Refresh </p> </body> </html> js7 13Computer Network & Web Tech (SET, JU)
  • 14. Windows Prompt – Taking User Input  If ‘Cancel’ clicked, value “null” submitted (absence of value)  Else, name entered is returned by windows.prompt (as string) and gets assigned to name variable name = windows.prompt (“Enter your name “);  Assignment statement  right side evaluated first  HTML loaded after dialog boxes dismissed 14Computer Network & Web Tech (SET, JU)
  • 15. Windows Alert  Predefined dialog box called ‘alert’ - used for popups <html> <head> <script> Window.alert(“Welcome to n Javascript n programming”); </script> </head> <body> <p > Click Refresh to run script again </p> </body> </html> js9 15Computer Network & Web Tech (SET, JU)
  • 16. Variables  Good practice to declare variables using <var>, not necessary  Value at time of declaration or later <head> <script> var sec_per_min=60; var min_per_hr=60; var hr_per_day=8; var secs_per_day; secs_per_day= sec_per_min * min_per_hr * hr_per_day; </script> </head> <body> <script> document.write(“A student studies”) document.write(secs_per_day + “ seconds per day </b>”); </script> </body> Js8,js10 16Computer Network & Web Tech (SET, JU)
  • 17. Variables - Loose typing  Variables can be assigned to data type without declaring  Javascript converts data type  + concatenation with string, addition with integer “My age is “ + 21  converts data to string  String is a group of characters 17Computer Network & Web Tech (SET, JU)
  • 18. Naming Variables  Case sensitive -> str, Str, STR different  Combination of characters – letters, digit, underscore, $  Does not begin with digit, cannot be a kerword  Valid - $val, _val, m_val, val7  Invalid - 7val Good programming practices • Use meaningful names – itemPrice • Comment purpose of variable at time of declaration // single-line comment /* Multiple line Comment */ 18Computer Network & Web Tech (SET, JU)
  • 19. Branching  If, if .. else …  Nested If… else if .. else if ..  Indentation good programming practice – increases readability  But note that else with previous if – better to use brackets If (x > 5) If (y>5) document. write (“x> 5 and y>5”) else document.write (“x<5”)  wrong 19Computer Network & Web Tech (SET, JU)
  • 20. Conditional If var name; var now=new date(); //current date and time var hr = now.getHours(); // current hour 0 - 23 If (hr <12 ) document. write (“Good morning”); else { hr=hr-12; if (hr < 6) document.write (“Good afternoon”) ; Else document.write(“Good evening”); } 20Computer Network & Web Tech (SET, JU)
  • 21. Looping  While  repetition on entry var cnt=0; while (cnt<5) { …. cnt ++; }  For  repetition on entry for (cnt=1; cnt<=7; ++cnt) cnt++, cnt+=1 for (loop=0; loop < width; loop++) { a_line = a_line + "x"; } var password="passport"; var answer; while (answer != password) { answer = prompt("What's the word?",""); } document.write(“<h1>That’s correct</h1>”); 21Computer Network & Web Tech (SET, JU)
  • 22. Labelled Break & Continue <script> Stop: { //labelled block for (var row=1; row <=10; ++row) { for (var col =1; col <=5; ++col) { if (row==5) break stop; document. write (“*”); } //end for document.writeln(“<br/>”); } //end for document.writeln(“This line should not print”); } // end block labelled stop document.writeln(“End of script”); </script> 22Computer Network & Web Tech (SET, JU)
  • 23. Javascript Functions • Divide and conquer using functions • Help in modularity, reusability • Avoid repeating pieces of code • Function invoked using name and arguments function myFunction(a, b) { return a * b; // Function returns the product of a and b } • Calling function asks called function to perform task and return task after result is done var x = myFunction(4, 3); // Function is called, return value 23Computer Network & Web Tech (SET, JU)
  • 24. Javascript Built-in Functions • Functions belong to Javascript objects called methods • Rich collection for string, date-time, array manipulations, calculations • Use such built-in functions - less development time, less chance of error function maximum(x, y, z) { return Math.max(x, Math.max(y, z); } <script> var input1 = windows.prompt(“Enter number 1”) var input2 = windows.prompt(“Enter number 2”) var input3 = windows.prompt(“Enter number 3”) var value1 = parseFloat(input1); var value2 = parseFloat(input2); var value3 = parseFloat(input3); var maxval = maximum(value1, value2, value3); </script> 24Computer Network & Web Tech (SET, JU)
  • 25. Javascript Objects var person = { firstName:“Akash", lastName:“Agarwal", age:50, eyeColor:"black" }; • Properties: name-value pairs • All instances of person object have same properties, but different values for these properties • Property can be accessed as objectName.propertyName or objectName["propertyName"] person.lastName; person["lastName"]; 25Computer Network & Web Tech (SET, JU)
  • 26. Object Methods var person = { firstName:“Akash", lastName:“Agarwal", age:50, eyeColor:"black“ fullName function() {return this.firstName + " " + this.lastName;} }; • Methods are actions that can be performed on objects • All methods of person object have same methods, but the methods are performed at different times • Methods can be accessed as objectName.methodName() person.fullName; 26Computer Network & Web Tech (SET, JU)
  • 27. String Object var txt = “testing**"; txt = “’testing’**"; var sln = txt.length; Series of characters / special characters *, _ , () etc. • Property - length • Escape characters used with quotes var x = "John"; var y = new String("John"); (x==y)  true as value same (x===y)  false as types different Also string objects cannot be compared 27Computer Network & Web Tech (SET, JU)
  • 28. String Methods charAt(index)  returns string containing character at index, or empty string if NA charCodeAt(index)  returns unicode value of character at position or NaN if NA If s= “ZEBRA” s. charAt(0)  “Z” ; s.charCodeAt(0) 90 If s=“TeStInG”, s1.LowerCase  “testing” ; s1.UpperCase  “TESTING” • fromCharCode(value1, value2)  Converts a list of unicode values to corresponding character string string.fromCharCode(87, 79, 82, 68)  “WORD” • s1.concat(s2)  concatenates s1 with s2, returns new string 28Computer Network & Web Tech (SET, JU)
  • 29. String Search Methods ltrl=“abcdefghidef” ltrl.indexOf(“def”) 3 ltrl.LastindexOf(“def”) 10 ltrl.LastindexOf(“def”,7) 10 ltrl.LastindexOf(“def”,10) 3 ltrl.searchf(“def”) 3 • Search() and indexOf() functions similar, differences are as follows: • search() method cannot take a second start position argument. • The search() method can take much more powerful search values (regular expressions) 29Computer Network & Web Tech (SET, JU)
  • 30. String Extraction Methods slice(start, end) var str = "Apple, Banana, Kiwi“ str.slice(7,13)  Banana str.slice(-12, -6)  Banana Omit the second parameter, the method will slice out the rest of the string substring(start, end) substring() is similar to slice(), except cannot receive negative inputs substr(start, length) substring() is similar to slice(), except 2nd parameter specifies length 30Computer Network & Web Tech (SET, JU)
  • 31. Replacing String Content replace() method replaces a specified value with another value in a string var str = "Apple, Banana, Kiwi“; var n =str.replace( “Banana “, “Orange”) ;  replace() does not change the string it is called on, returns a new string  replaces only first occurrence until /g option specified n = str.replace(/an/g, “st");  Case sensitive method  To replace case insensitive, use a regular expression with an /i flag n = str.replace(/AN/i, “st"); 31Computer Network & Web Tech (SET, JU)
  • 32. Math Object Math.round(4.5)  5 Math.round(4.4) 4 Math.ceil(4.2)  5 Math.ceil(-4.2)  -4 Math.floor(x) Math.abs(-2.7)  2.7 Math.pow(8, 2)  64 (x to the power y) Math.exp(x)  (e to the power x) exp(1.0)  2.718 Math.log(x)  (natural log base e of x) log(2.718) 1.0 max(2.3, 12.7)  12.7 min(-2.3, -12.7)  -12.7 sin(x), cos(x), tan(x), sqrt(x) CONSTANTS Math.PI  22/7, Math.SQRT2 1.414, Math.E  2.718, Math.LN20.693 32Computer Network & Web Tech (SET, JU)
  • 33. Date Object getDate() Get the day as a number (1-31) getUTCDate() Get the day as in Universal Time Zone getDay() Get the weekday as a number (0-6) getFullYear() Get the four digit year (yyyy) getHours() Get the hour (0-23) getMilliseconds() Get the milliseconds (0-999) getMinutes() Get the minutes (0-59) getMonth() Get the month (0-11) getSeconds() Get the seconds (0-59) getTime() Get the time (milliseconds since January 1, 1970) setDate(val) Set the day as a number (1-31), can add number d.setDate(d.getDate() + 50); setFullYear(y,m,d) m,d optional, if not mentioned default from current date 33Computer Network & Web Tech (SET, JU)
  • 34. Working with Date Object Parsing Dates Date.parse() returns the number of milliseconds between the date and January 1, 1970 from a valid string <script> var msec = Date.parse("March 17, 2015"); document.getElementById("demo").innerHTML = msec; </script> Comparing Dates today = new Date(); someday = new Date(); someday.setFullYear(2100, 0, 14); if (someday > today) { text = "Today is before January 14, 2100.";} else { text = "Today is after January 14, 2100."; } 34Computer Network & Web Tech (SET, JU)
  • 35. Number Object var x = 9.656; x.toString() Returns string “9.656” in place of number x.fixed(2) Returns specified number of decimals i.e. 9.66 x.toPrecision(2) Returns 9.7 x.valueOf Returns numeric value from object or other data type var b= new boolean(true) b.toString  “true” b.valueOf ()  1 35Computer Network & Web Tech (SET, JU)
  • 36. Converting Variables to Numbers number() Returns a number, converted from its argument parseInt() Parses a string and returns a whole number* parseFloat() Parses a string and returns a number* *Spaces are allowed. Only the first number is returned x = true; Number(x); // returns 1 parseInt("10.33"); // returns 10 parseFloat("10.33"); // returns 10.33 x = "10 20" Number(x); // returns NaN 36Computer Network & Web Tech (SET, JU)
  • 37. Arrays  Data structure consisting of related data items  Group of memory locations that have same name, usually same data type  Used to allocate memory, instantiate object var c=new Array(12)  elements not initialized, undefined Initialization for var i=0; i < c.length, ++i) c[i] = i  length of array c // iterate through elements of array using for .. In for (var i in theArray) total +=theArray[i] Definition & initialization together var n = new Array (10, 20, 30, 40, 50); 37Computer Network & Web Tech (SET, JU)
  • 38. Declaring & Allocating Arrays  Arrays use space in memory  ‘new’ dynamic memory location operator  Referred using []  Number within square bracket indicates size during declaration  Called subscript or index  Arr_name[0] –refers to first element arr_name[6]  7th element  c.length  length of array c  Arrays used when you want the element names to be numbers  If a=6, b=5, c[a+b]+=2  Increment c[11] by 2 38Computer Network & Web Tech (SET, JU)
  • 39. Pass By Reference  Pass by value  when arguments passed, copy of arguments value is made and passed to calling function (numbers, strings, boolean values)  Pass by reference  caller gives called function direct access to caller’s data and also allows to modify it  Address of memory location where data resides is passed (objects, arrays passed by reference) 39Computer Network & Web Tech (SET, JU)
  • 40. Linear Search in Arrays  Var a = [10, 9, 1, 3, 5, 7] function linearSearch(a, key) { for (var n=0; n<a.length, ++n) if ( a[n] == key) return n; return -1; } 40Computer Network & Web Tech (SET, JU)
  • 41. Sorting Arrays  Var a = [10, 9, 1, 3, 5, 7] function compareInt(val1, val2) {return parseInt(val1) – parseInt(val(2)) Complete sort function using this… 41Computer Network & Web Tech (SET, JU)
  • 42. Split & Join Functions  Split function to split string into array elements vary parts = "cpu,disk,memory,monitor,keyboard,mouse"; var parts_array = parts.split(","); for (loop=0; loop < parts_array.length; loop++) { document.writeln("A computer has " + parts_array[loop] + ".<br>"); } Join method of array to join string, may use different delimiter document.getElementById(“output”).value = parts_array.join(“n”); 42Computer Network & Web Tech (SET, JU)
  • 43. Window Object  Used for manipulating browser window window.open(URL, name, options)  creates new window with URL and name as mentioned, visible features set by options window.prompt(prompt)  displays user box asking foruser input windows.close  close current window & delete object from memory windows.focus  set focus to that window windows.blur  take away focus windows.document  property  document object representing the visible document in the window windows.closed  property boolean value, true if window closed 43Computer Network & Web Tech (SET, JU)
  • 44. Document Object  Used for manipulating the document visible in browser window write(string)  write string to HTML doc as HTML code writeln(string)  write as above, add a line feed Each such “write” resumes writing where stopped before. For writeln, next write begins on new line <script> document.write(“<h1 style =”color : red ” >”);  modify to display in red document.write(“Welcome to programming in Javascript “ </h1> “); </script> 44Computer Network & Web Tech (SET, JU)
  • 45. Document Object  One can write multiple lines using single sentence writeln(“ Welcome to <br/> programming <br/> in Javascript”)  Use “+” operator to split statement over multiple line, but rendered as single line <script> document.write(“<h1 style =”color : red ” >”);  modify to display in red document.write(“Welcome to programming in” + “Javascript” </h1>”); </script> 45Computer Network & Web Tech (SET, JU)
  • 46. Document Object Model  When browser loads a page, creates a DOM for page  Gives access to all elements in page  Using JS, elements in page can be created, modified, removed Modelling a Document: DOM Nodes & Trees Every element in HTML page is modelled by web browser as DOM node Nodes in a document together make up a tree – Describes relationship among nodes − Nodes related among each other using parent-child relationship − HTML element inside another – container element parent, contained element child − Nodes may have multiple children, but only single parent 46Computer Network & Web Tech (SET, JU)
  • 47. Document Object Model 47Computer Network & Web Tech (SET, JU)
  • 48. Demonstration of TREE <html> <head> <title> DOM Tree Demo </title> </head> <body> <h1> HTML Page </h1> <p> Here is the list: </p> <ul > <li>One</li> <li>Two</li> </ul> </body> </html> -#document - html - head -title #text - body - h1 #text -#text -p #text -#text - ul -li #text -li #text 48Computer Network & Web Tech (SET, JU)
  • 49. Document Object Model  Standard object model and programming interface for HTML  HTML DOM defines:  HTML elements as objects  Properties of all HTML elements  Methods to access all HTML elements  Events for all HTML elements <script> document.getElementById(“Hello”).innerHTML=“Hello”; </script> </html> Methods document.getElementByTagName(name)  find elements by tagname document.getElementByClassName(name)  nonunique, array 49Computer Network & Web Tech (SET, JU)
  • 50. Document Object Model  The HTML DOM is a standard for how to get, change, add, or delete HTML elements (nodes) dynamically  Also used to  Change attributes , CSS styles in the page  React to all existing HTML events in the page  Create new events in the page Adding & Deleting Elements document.createElement(name) document.removeChild(name) document.appendChild(name) document.replaceChild(new, old) Changing attributes & styles element.innerHTML = new html content element.attribute= new value; element.setAttribute(attribute,value) element.style.proerty= new style 50Computer Network & Web Tech (SET, JU)
  • 51. Traversing & Modifying DOM Tree  Create New Node <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);  add text to p var element = document.getElementById("div1"); element.appendChild(para);  add as last node of div1 </script> var element = document.getElementById("div1"); var child = document.getElementById("p1"); element.insertBefore(para, child);  add before p1 51Computer Network & Web Tech (SET, JU)
  • 52. Traversing & Modifying DOM Tree  Remove Existing Node <script> var parent = document.getElementById("div1"); var child = document.getElementById("p1"); parent.removeChild(child); </script>  Replace Child <script> var para = document.createElement("p"); var node = document.createTextNode("This is new."); para.appendChild(node); var parent = document.getElementById("div1"); var child = document.getElementById("p1"); parent.replaceChild(para, child); </script> 52Computer Network & Web Tech (SET, JU)
  • 53. Document Object Properties document.cookie  Returns document’s cookie (Piece of data in user’s computer maintaining information about client during & in between sessions)  Contains name-value pairs separated by semicolon if (document.cookie) { var myCookie=unescape(document.Cookie); var cookieTokens =myCookie.split(“;“) name = cookieTokens[i] } 53Computer Network & Web Tech (SET, JU)
  • 54. Document Object Properties document.anchors Returns all <a> elements that have a name attribut document.URI Returns URI of document document.domain Returns domain name of document server document.lastModified Returns the date and time the document was updated document.links Returns all elements that have a href attribute document.title Returns title of document 54Computer Network & Web Tech (SET, JU)

Editor's Notes

  • #38: For .. In skips undefined elements
  • #47: Some browsers like Firefox allow instlln of tool called DOM inspector
  • #49: Title has child text node - containing text White spaces also treated as text in firefox
  • #50: Methods action to perform, properties that can be set getElementByID  returns DOM node representing element Document owner of all objects page innerHTML  property