JavaScript Object Model
Biggest Advantage of JavaScript I can access values of HTML elements using JavaScript I can modify values of HTML elements using JavaScript
Disadvantage of JavaScript Each browser has its own document object Model
Initial JavaScript Object Model
New JavaScript Object Model
New Properties added in Latest JavaScript Model all[]  Children[]  className innerHTML  innterText outerHTML outerText
New Properties added in Latest JavaScript Model parentElement  style tagName
New methods added in Latest JavaScript Model Click() getAttribute() insertAdjacentHTML() insertAdjacentText() setAttribute() removeAttribute()
Difference between Initial Model and New model Slide No. 7 and 9 shows the new methods and new properties Slide no.5 blue circles shows the new objects added in Latest JavaScript Model
How to use these Object Model We have been doing this in our previous lecture, but I will take few more examples now.
Sample Code <body bgcolor=&quot;white&quot; text=&quot;green&quot; link=&quot;red&quot; alink=&quot;#ffff00&quot;> <h1 align=&quot;center&quot;>Test Document</h1> <hr /> <a href=&quot;http://www.pint.com/&quot;>Sample link</a> <a name=&quot;anchor1&quot;></a> <a name=&quot;anchor2&quot; href=&quot;http://www.javascriptref.com&quot;>Sample link 2</a> <form name=&quot;form1&quot; action=&quot;#&quot; method=&quot;get&quot;></form> <form name=&quot;form2&quot; action=&quot;#&quot; method=&quot;get&quot;></form> <hr /> <br /><br />
How many Forms are there? Use object  forms[] document.forms[]  is an array document.forms.length  returns the number of forms in the web page document.forms[0]  is the first form, OR document.form1  is the first form document.forms[0].name  returns the name of first form i.e. form1
Code to Access All Forms if ( document.forms.length  > 0) { document.write(&quot;<h2>Forms</h2>&quot;); document.write(&quot;# Forms = &quot; +  document.forms.length  + &quot;<br />&quot;); for (i=0; i <  document.forms.length ; i++)  document.write(&quot;Forms[&quot;+i+&quot;]=&quot; +  document.forms[i].name  + &quot;<br />&quot;); }
How many anchors are there? Use object  anchors[] document.anchors[]  is an array document.anchors.length  returns the number of anchors in the web page document.anchors[0]  is the first anchor, OR document.anchor1  is the first anchor
Code to Access all anchors if ( document.anchors.length  > 0) {  document.write(&quot;<h2>Anchors</h2>&quot;); document.write(&quot;# Anchors = &quot; +  document.anchors.length  + &quot;<br />&quot;); for (i=0; i <  document.anchors.length ; i++) document.write(&quot;Anchors[&quot;+i+&quot;]=&quot; +  document.anchors[i]  + &quot;<br />&quot;); }
How many links are there? Use object  links[] document.links[]  is an array document.links.length  returns the number of links in the web page document.links[0]  is the first link , OR document. name of link  is the first link (In our example, we didn’t use any any name for link)
Other Properties document.bgColor   - returns the background color of web page document.fgColor  – returns the foreground color of web page. document.location  – returns the location of web page i.e URL document.URL  – returns the URL of web page document.title  – returns the title of web page.
More properties document.alinkColor  – returns the active link color document.vlinkColor  – returns the visited link color. document.linkColor  – returns the link color. Slide 12-18 were based on oldest JavaScript Model.
Sample Code <body> <form action=&quot;#&quot; method=&quot;get&quot;> <input type=&quot;text&quot; /> </form> <br /><br /> <form action=&quot;#&quot; method=&quot;get&quot;> <input type=&quot;text&quot; /> <br /> <input type=&quot;text&quot; /> </form> </body>
Using elements[] To access 1 st  form, I can write document.forms[0] To access 2 nd  form, I can write document.forms[1] To access 1 st  text box inside 2 nd  form document.forms[1]. elements[0] To access 2 nd  text box inside 1 st  form document.forms[1]. elements[1]
Using elements[] elements can be radio button, text box, check box etc .  Also called as  form elements. elements[]  is defined inside  forms[]  , (Refer slide 4 and 5). elements.length  return the number of elements inside a particular form. elements[0]  refer to 1 st  element,  elements[1]  refer to 2 nd  element and so on.
2 nd  Method of accessing elements By using name attribute of elements. (We discussed this with forms and anchors and links)
2 nd  method of accessing elements <form name=&quot;myForm&quot; id=&quot;myForm&quot; method=&quot;get&quot; action=&quot;#&quot;> <input type=&quot;text&quot; name=&quot;userName&quot; id=&quot;userName&quot; /> </form> document.myForm.userName  refer to the text box inside form.
3 rd  method of accessing elements Using  getElementById() Element that we want to access must have its  id attribute defined
Example of getElementById <body> <p id=&quot;p1&quot;> this is a  paragraph </p> <input type=&quot;button&quot; value=&quot;Click&quot; onClick=&quot;butClick()&quot;> </body> pid =  document.getElementById(“p1”) ; p1.align = “right”;
document.getElementById pid =getElementById(“p1”) Returns the reference of object <p1>and store it in pid. pid.align = “right” This will align the paragraph with id=p1 to the right By Id we can get access to any element in the web page.
document.all[] document.all[]  – return array of all html tags in the web page. i.e.  document.all.length  is the count of number of tags in web page. document.all[0]  returns the reference of 1 st  tag. document.all[1]  retuns the reference of 2 nd  tag. Introduced by Internet Explorer
Example <body> <h1>Example Heading</h1> <hr /> <p>This is a <em>paragraph</em>.  It is only a <em>paragraph.</em></p> <p>Yet another <em>paragraph.</em></p> <p>This final <em>paragraph</em> has <em id=&quot;special&quot;>special emphasis.</em></p> <hr /> </body>
How many tags are there document.all.length , returns the number of tag in the web page.
What are the name of tags <script language=&quot;JavaScript&quot;> var no =  document.all.length ; alert(no); for(i=0;i<no;i++) document.write(&quot;<br>“  +  document.all[i].tagName ); </script>
Output Total number of tags: 16 HTML HEAD TITLE BODY H1 HR P EM EM P EM P EM EM HR SCRIPT
Final Note We will learn about  more  JavaScript Object introduced by new browsers in next chapter.

More Related Content

PPTX
Css ppt - Cascading Style Sheets
PPT
JavaScript Workshop
PPTX
Javascript MCQ
PPS
Advisor Jumpstart: JavaScript
PDF
GraphQL - when REST API is not enough - lessons learned
PPT
WPF Controls
PPT
Agile Development With Hobo
PDF
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademy
Css ppt - Cascading Style Sheets
JavaScript Workshop
Javascript MCQ
Advisor Jumpstart: JavaScript
GraphQL - when REST API is not enough - lessons learned
WPF Controls
Agile Development With Hobo
GraphQL - Piękne API w Twojej Aplikacji - KrakowGraphAcademy

Viewers also liked (8)

PPT
Pravim slike
PPTX
Onderwijs overleg 4 april 2013
DOC
Lecture6 analogdigitalsignals
 
PPT
rockkkkkkk
PPT
מצגת יום הזיכרון
PPT
nutrition in first 2 months of our study
PDF
40 54 Pages Sy X
PDF
Pravim slike
Onderwijs overleg 4 april 2013
Lecture6 analogdigitalsignals
 
rockkkkkkk
מצגת יום הזיכרון
nutrition in first 2 months of our study
40 54 Pages Sy X
Ad

Similar to Week32 (20)

PDF
Week32
 
PPT
Javascript: Ajax & DOM Manipulation v1.2
PPT
C5 Javascript
PPT
Javascript Primer
PDF
Modern JavaScript Programming
PPT
lecture 6 javascript event and event handling.ppt
PPT
Java Script
PPTX
Introduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps
PPT
JavaScript & Dom Manipulation
PPT
Lecture 5 - Comm Lab: Web @ ITP
PDF
05 JavaScript #burningkeyboards
PPTX
Java Script - A New Look
PPTX
DOM and Events
PPT
eXo SEA - JavaScript Introduction Training
ODP
JavaScript and jQuery Fundamentals
PPT
Scripting The Dom
PPT
The Theory Of The Dom
PPT
Reversing JavaScript
PPT
Effecient javascript
PPT
JavaScript
Week32
 
Javascript: Ajax & DOM Manipulation v1.2
C5 Javascript
Javascript Primer
Modern JavaScript Programming
lecture 6 javascript event and event handling.ppt
Java Script
Introduction to JSON and Building Youtube, Twitter and Wikipedia Web Apps
JavaScript & Dom Manipulation
Lecture 5 - Comm Lab: Web @ ITP
05 JavaScript #burningkeyboards
Java Script - A New Look
DOM and Events
eXo SEA - JavaScript Introduction Training
JavaScript and jQuery Fundamentals
Scripting The Dom
The Theory Of The Dom
Reversing JavaScript
Effecient javascript
JavaScript
Ad

More from H K (20)

PDF
Assignment4
 
DOCX
Assignment3
 
PDF
Induction
 
PDF
Solution3
 
PDF
Solution2
 
DOCX
Mid-
 
PDF
Assignment4
 
PDF
Assignment4
 
PDF
Dm assignment3
 
PPT
Proof
 
PDF
Resolution
 
DOCX
Assignment description
 
PDF
Dm assignment2
 
PDF
Set
 
PDF
Dm assignment1
 
PPTX
Logic
 
DOCX
Introduction
 
PDF
Assignment 2 sol
 
PDF
Assignment sw solution
 
PDF
Violinphoenix
 
Assignment4
 
Assignment3
 
Induction
 
Solution3
 
Solution2
 
Mid-
 
Assignment4
 
Assignment4
 
Dm assignment3
 
Proof
 
Resolution
 
Assignment description
 
Dm assignment2
 
Set
 
Dm assignment1
 
Logic
 
Introduction
 
Assignment 2 sol
 
Assignment sw solution
 
Violinphoenix
 

Recently uploaded (20)

PDF
Consumable AI The What, Why & How for Small Teams.pdf
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Zenith AI: Advanced Artificial Intelligence
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PPTX
Configure Apache Mutual Authentication
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
Microsoft Excel 365/2024 Beginner's training
PPTX
Modernising the Digital Integration Hub
PDF
CloudStack 4.21: First Look Webinar slides
PPTX
Chapter 5: Probability Theory and Statistics
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PPTX
Build Your First AI Agent with UiPath.pptx
PPTX
2018-HIPAA-Renewal-Training for executives
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPT
What is a Computer? Input Devices /output devices
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Consumable AI The What, Why & How for Small Teams.pdf
Developing a website for English-speaking practice to English as a foreign la...
NewMind AI Weekly Chronicles – August ’25 Week III
Zenith AI: Advanced Artificial Intelligence
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Getting started with AI Agents and Multi-Agent Systems
Improvisation in detection of pomegranate leaf disease using transfer learni...
Configure Apache Mutual Authentication
sustainability-14-14877-v2.pddhzftheheeeee
Microsoft Excel 365/2024 Beginner's training
Modernising the Digital Integration Hub
CloudStack 4.21: First Look Webinar slides
Chapter 5: Probability Theory and Statistics
Module 1.ppt Iot fundamentals and Architecture
A proposed approach for plagiarism detection in Myanmar Unicode text
Build Your First AI Agent with UiPath.pptx
2018-HIPAA-Renewal-Training for executives
A contest of sentiment analysis: k-nearest neighbor versus neural network
What is a Computer? Input Devices /output devices
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor

Week32

  • 2. Biggest Advantage of JavaScript I can access values of HTML elements using JavaScript I can modify values of HTML elements using JavaScript
  • 3. Disadvantage of JavaScript Each browser has its own document object Model
  • 6. New Properties added in Latest JavaScript Model all[] Children[] className innerHTML innterText outerHTML outerText
  • 7. New Properties added in Latest JavaScript Model parentElement style tagName
  • 8. New methods added in Latest JavaScript Model Click() getAttribute() insertAdjacentHTML() insertAdjacentText() setAttribute() removeAttribute()
  • 9. Difference between Initial Model and New model Slide No. 7 and 9 shows the new methods and new properties Slide no.5 blue circles shows the new objects added in Latest JavaScript Model
  • 10. How to use these Object Model We have been doing this in our previous lecture, but I will take few more examples now.
  • 11. Sample Code <body bgcolor=&quot;white&quot; text=&quot;green&quot; link=&quot;red&quot; alink=&quot;#ffff00&quot;> <h1 align=&quot;center&quot;>Test Document</h1> <hr /> <a href=&quot;http://www.pint.com/&quot;>Sample link</a> <a name=&quot;anchor1&quot;></a> <a name=&quot;anchor2&quot; href=&quot;http://www.javascriptref.com&quot;>Sample link 2</a> <form name=&quot;form1&quot; action=&quot;#&quot; method=&quot;get&quot;></form> <form name=&quot;form2&quot; action=&quot;#&quot; method=&quot;get&quot;></form> <hr /> <br /><br />
  • 12. How many Forms are there? Use object forms[] document.forms[] is an array document.forms.length returns the number of forms in the web page document.forms[0] is the first form, OR document.form1 is the first form document.forms[0].name returns the name of first form i.e. form1
  • 13. Code to Access All Forms if ( document.forms.length > 0) { document.write(&quot;<h2>Forms</h2>&quot;); document.write(&quot;# Forms = &quot; + document.forms.length + &quot;<br />&quot;); for (i=0; i < document.forms.length ; i++) document.write(&quot;Forms[&quot;+i+&quot;]=&quot; + document.forms[i].name + &quot;<br />&quot;); }
  • 14. How many anchors are there? Use object anchors[] document.anchors[] is an array document.anchors.length returns the number of anchors in the web page document.anchors[0] is the first anchor, OR document.anchor1 is the first anchor
  • 15. Code to Access all anchors if ( document.anchors.length > 0) { document.write(&quot;<h2>Anchors</h2>&quot;); document.write(&quot;# Anchors = &quot; + document.anchors.length + &quot;<br />&quot;); for (i=0; i < document.anchors.length ; i++) document.write(&quot;Anchors[&quot;+i+&quot;]=&quot; + document.anchors[i] + &quot;<br />&quot;); }
  • 16. How many links are there? Use object links[] document.links[] is an array document.links.length returns the number of links in the web page document.links[0] is the first link , OR document. name of link is the first link (In our example, we didn’t use any any name for link)
  • 17. Other Properties document.bgColor - returns the background color of web page document.fgColor – returns the foreground color of web page. document.location – returns the location of web page i.e URL document.URL – returns the URL of web page document.title – returns the title of web page.
  • 18. More properties document.alinkColor – returns the active link color document.vlinkColor – returns the visited link color. document.linkColor – returns the link color. Slide 12-18 were based on oldest JavaScript Model.
  • 19. Sample Code <body> <form action=&quot;#&quot; method=&quot;get&quot;> <input type=&quot;text&quot; /> </form> <br /><br /> <form action=&quot;#&quot; method=&quot;get&quot;> <input type=&quot;text&quot; /> <br /> <input type=&quot;text&quot; /> </form> </body>
  • 20. Using elements[] To access 1 st form, I can write document.forms[0] To access 2 nd form, I can write document.forms[1] To access 1 st text box inside 2 nd form document.forms[1]. elements[0] To access 2 nd text box inside 1 st form document.forms[1]. elements[1]
  • 21. Using elements[] elements can be radio button, text box, check box etc . Also called as form elements. elements[] is defined inside forms[] , (Refer slide 4 and 5). elements.length return the number of elements inside a particular form. elements[0] refer to 1 st element, elements[1] refer to 2 nd element and so on.
  • 22. 2 nd Method of accessing elements By using name attribute of elements. (We discussed this with forms and anchors and links)
  • 23. 2 nd method of accessing elements <form name=&quot;myForm&quot; id=&quot;myForm&quot; method=&quot;get&quot; action=&quot;#&quot;> <input type=&quot;text&quot; name=&quot;userName&quot; id=&quot;userName&quot; /> </form> document.myForm.userName refer to the text box inside form.
  • 24. 3 rd method of accessing elements Using getElementById() Element that we want to access must have its id attribute defined
  • 25. Example of getElementById <body> <p id=&quot;p1&quot;> this is a paragraph </p> <input type=&quot;button&quot; value=&quot;Click&quot; onClick=&quot;butClick()&quot;> </body> pid = document.getElementById(“p1”) ; p1.align = “right”;
  • 26. document.getElementById pid =getElementById(“p1”) Returns the reference of object <p1>and store it in pid. pid.align = “right” This will align the paragraph with id=p1 to the right By Id we can get access to any element in the web page.
  • 27. document.all[] document.all[] – return array of all html tags in the web page. i.e. document.all.length is the count of number of tags in web page. document.all[0] returns the reference of 1 st tag. document.all[1] retuns the reference of 2 nd tag. Introduced by Internet Explorer
  • 28. Example <body> <h1>Example Heading</h1> <hr /> <p>This is a <em>paragraph</em>. It is only a <em>paragraph.</em></p> <p>Yet another <em>paragraph.</em></p> <p>This final <em>paragraph</em> has <em id=&quot;special&quot;>special emphasis.</em></p> <hr /> </body>
  • 29. How many tags are there document.all.length , returns the number of tag in the web page.
  • 30. What are the name of tags <script language=&quot;JavaScript&quot;> var no = document.all.length ; alert(no); for(i=0;i<no;i++) document.write(&quot;<br>“ + document.all[i].tagName ); </script>
  • 31. Output Total number of tags: 16 HTML HEAD TITLE BODY H1 HR P EM EM P EM P EM EM HR SCRIPT
  • 32. Final Note We will learn about more JavaScript Object introduced by new browsers in next chapter.