SlideShare ist ein Scribd-Unternehmen logo
1 von 19
The DOM tree1
The DOM tree
2
Types of DOM nodes
 element nodes (HTML tag)
 can have children and/or attributes
 text nodes (text in a block element)
 attribute nodes (attribute/value pair)
 text/attributes are children in an element node
 cannot have children or attributes
 not usually shown when drawing the DOM tree
3
<p>
This is a paragraph of text with a
<a href="/path/page.html">link in it</a>.
</p> HTML
Types of DOM nodes
4
<p>
This is a paragraph of text with a
<a href="/path/page.html">link in it</a>.
</p> HTML
Traversing the DOM tree
name(s) description
firstChild, lastChild
start/end of this node's list of
children
childNodes
array of all this node's
children
nextSibling, previousSibling
neighboring nodes with the
same parent
parentNode
the element that contains this
node
5
DOM tree traversal example
6
<p id="foo">This is a paragraph of text with a
<a href="/path/to/another/page.html">link</a>.</p>
HTML
Elements vs text nodes
 Q: How many children does the div above
have?
 A: 3
 an element node representing the <p>
 two text nodes representing "nt" (before/after the
paragraph)
 Q: How many children does the paragraph
7
<div>
<p>
This is a paragraph of text with a
<a href="page.html">link</a>.
</p>
</div> HTML
8
Adding Some Text To A Page
There are five steps:
1. Create a new Element
2. Create new Text
3. Append the new Text to the new Element
4. Find an existing Element
5. Append the new Element to the existing
Element
9
1. Create New Element Node
Let us, say create a new <p> tag (element) so
that we can attach some text to it
For convenience, we can put the new object into
a variable
var newNode;
newNode = document.createElement(“p”)
10
2. Create a Text Node
Next, create a text node
Again, for convenience, we can put the new text
node into a variable
var newText;
newText = document.createTextNode(“Some text.”)
11
3. Attach the New Text Node to the
New Element
To put the text into the page, we have to attach
the text node to the new HTML element:
newNode.appendChild(newText);
12
4.Find an Existing Element
The new element with our text node attached to
it is still floating around in a Javascript world.
We need to find an existing element so that we
can attach it
For convenience, we shall put this existing
element into a variable
var docElement;
docElement = document.getElementById(“thisLocation”);
13
5. Append the New Element to the
Existing Element
To insert our text into the page, we now have to
append the new element to the existing
element
docElement.appendChild(newNode);
14
Putting the 5 Steps Together
<head>
<script language="javascript" type="text/javascript">
var myText;
myText = "This is new text to be added to the page dynamically.";
function addText(location) {
var newNode;
var newText;
var docElement;
newNode = document.createElement("p");
newText = document.createTextNode(myText);
newNode.appendChild(newText);
docElement = document.getElementById(location);
docElement.appendChild(newNode);
}</script>
</head>
<body>
<p><a href="#" onclick="addText('thisLocation');">Click to add new text to the page</a></p>
<p id="thisLocation">New text will appear below here</p>
<p>Some further text in the page</p>
</body>
15
Attribute Nodes
 We can get at the attributes of an element
through attribute nodes
 Attribute nodes, like text nodes are always
contained in element nodes
 We shall look at methods:
 getAttribute()
 setAttribute()
16
Getting Attribute Nodes
 Hands On
 Create a file JavascriptDOM.html
 Add this code to alert the attribute of an element:
function dispAttribs() {
var messg;
attribs = new Array;
attribs = document.getElementsByTagName("p");
for (i = 0; i < attribs.length; i++) {
messg = attribs[i].getAttribute("className");
alert(messg);
}
}
 Add this to the bottom of the body:
<p onclick="dispAttribs();">Click here to see class attributes</p>
 Try this in Firefox
 Point to consider: why is this attribute called ‘className’?
17
Setting Attribute Nodes
 Hands On
 Create the file JavascriptDOM.html
 Add this code to change the attribute of an element:
function chngAttribs() {
var messg;
attribs = new Array;
attribs = document.getElementsByTagName("p");
for (i = 0; i < attribs.length; i++) {
attribs[i].setAttribute("className","jazz");
}
}
 Add this to the bottom of the body:
<p onclick="chngAttribs();">Click here to change class
attributes</p>
18
User inserts and removes text
 Hands On
 Crate file JavascriptDOM.html
 Place code in this page so that:
 When the user mouseovers on an image, the
relevant text appears
 When the user mouseouts on an image, the text
disappears
Removing a node from the
page19
function slideClick() {
var bullets = document.getElementsByTagName("li");
for (var i = 0; i < bullets.length; i++) {
if (bullets[i].innerHTML.indexOf("children")
>= 0) {
bullets[i].remove();
}
}
} JS
 each DOM object has a removeChild method
to remove its children from the page
 Prototype adds a remove method for a node to
remove itself

Weitere ähnliche Inhalte

Was ist angesagt?

Control Strategies in AI
Control Strategies in AI Control Strategies in AI
Control Strategies in AI Bharat Bhushan
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2EPAM Systems
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perlsana mateen
 
Leaky Bucket & Tocken Bucket - Traffic shaping
Leaky Bucket & Tocken Bucket - Traffic shapingLeaky Bucket & Tocken Bucket - Traffic shaping
Leaky Bucket & Tocken Bucket - Traffic shapingVimal Dewangan
 
Bayesian networks in AI
Bayesian networks in AIBayesian networks in AI
Bayesian networks in AIByoung-Hee Kim
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptMuhammadRehan856177
 
Scripting languages
Scripting languagesScripting languages
Scripting languagesteach4uin
 
Document object model
Document object modelDocument object model
Document object modelAmit kumar
 
Wireless Markup Language
Wireless Markup LanguageWireless Markup Language
Wireless Markup LanguageHitesh Piprotar
 
Data Streaming For Big Data
Data Streaming For Big DataData Streaming For Big Data
Data Streaming For Big DataSeval Çapraz
 
Artificial intelligence and knowledge representation
Artificial intelligence and knowledge representationArtificial intelligence and knowledge representation
Artificial intelligence and knowledge representationSajan Sahu
 
Mining Data Streams
Mining Data StreamsMining Data Streams
Mining Data StreamsSujaAldrin
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 

Was ist angesagt? (20)

Control Strategies in AI
Control Strategies in AI Control Strategies in AI
Control Strategies in AI
 
Sgml
SgmlSgml
Sgml
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
 
Adversarial search
Adversarial search Adversarial search
Adversarial search
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Leaky Bucket & Tocken Bucket - Traffic shaping
Leaky Bucket & Tocken Bucket - Traffic shapingLeaky Bucket & Tocken Bucket - Traffic shaping
Leaky Bucket & Tocken Bucket - Traffic shaping
 
Bayesian networks in AI
Bayesian networks in AIBayesian networks in AI
Bayesian networks in AI
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).ppt
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
Document object model
Document object modelDocument object model
Document object model
 
Wireless Markup Language
Wireless Markup LanguageWireless Markup Language
Wireless Markup Language
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Data Streaming For Big Data
Data Streaming For Big DataData Streaming For Big Data
Data Streaming For Big Data
 
Artificial intelligence and knowledge representation
Artificial intelligence and knowledge representationArtificial intelligence and knowledge representation
Artificial intelligence and knowledge representation
 
Xml namespace
Xml namespaceXml namespace
Xml namespace
 
Mining Data Streams
Mining Data StreamsMining Data Streams
Mining Data Streams
 
Sliding window protocol
Sliding window protocolSliding window protocol
Sliding window protocol
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 

Ähnlich wie INTRODUCTION TO DOM AND DOM TREE

Html dom part-ii
Html dom part-iiHtml dom part-ii
Html dom part-iiH K
 
Java Script and HTML.
Java Script and HTML.Java Script and HTML.
Java Script and HTML.Akshat Vig
 
Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance TipsRavi Raj
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)mussawir20
 
Introduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and JqueryIntroduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and Jqueryvaluebound
 
12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objectsPhúc Đỗ
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulationborkweb
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generationPaul Graham
 

Ähnlich wie INTRODUCTION TO DOM AND DOM TREE (20)

DOM and Events
DOM and EventsDOM and Events
DOM and Events
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
 
DOM Quick Overview
DOM Quick OverviewDOM Quick Overview
DOM Quick Overview
 
Java script
Java scriptJava script
Java script
 
Html dom part-ii
Html dom part-iiHtml dom part-ii
Html dom part-ii
 
Automating Ievb
Automating IevbAutomating Ievb
Automating Ievb
 
Dom
Dom Dom
Dom
 
Java Script and HTML.
Java Script and HTML.Java Script and HTML.
Java Script and HTML.
 
Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance Tips
 
Element
ElementElement
Element
 
Ext Js Dom Helper
Ext Js Dom HelperExt Js Dom Helper
Ext Js Dom Helper
 
C5 Javascript
C5 JavascriptC5 Javascript
C5 Javascript
 
Prototype Utility Methods(1)
Prototype Utility Methods(1)Prototype Utility Methods(1)
Prototype Utility Methods(1)
 
Introduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and JqueryIntroduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and Jquery
 
12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objects
 
Javascript.ppt
Javascript.pptJavascript.ppt
Javascript.ppt
 
HTML and CSS Basics
HTML and CSS BasicsHTML and CSS Basics
HTML and CSS Basics
 
JavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM ManipulationJavaScript: Ajax & DOM Manipulation
JavaScript: Ajax & DOM Manipulation
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
EPiServer report generation
EPiServer report generationEPiServer report generation
EPiServer report generation
 

Kürzlich hochgeladen

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Kürzlich hochgeladen (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

INTRODUCTION TO DOM AND DOM TREE

  • 3. Types of DOM nodes  element nodes (HTML tag)  can have children and/or attributes  text nodes (text in a block element)  attribute nodes (attribute/value pair)  text/attributes are children in an element node  cannot have children or attributes  not usually shown when drawing the DOM tree 3 <p> This is a paragraph of text with a <a href="/path/page.html">link in it</a>. </p> HTML
  • 4. Types of DOM nodes 4 <p> This is a paragraph of text with a <a href="/path/page.html">link in it</a>. </p> HTML
  • 5. Traversing the DOM tree name(s) description firstChild, lastChild start/end of this node's list of children childNodes array of all this node's children nextSibling, previousSibling neighboring nodes with the same parent parentNode the element that contains this node 5
  • 6. DOM tree traversal example 6 <p id="foo">This is a paragraph of text with a <a href="/path/to/another/page.html">link</a>.</p> HTML
  • 7. Elements vs text nodes  Q: How many children does the div above have?  A: 3  an element node representing the <p>  two text nodes representing "nt" (before/after the paragraph)  Q: How many children does the paragraph 7 <div> <p> This is a paragraph of text with a <a href="page.html">link</a>. </p> </div> HTML
  • 8. 8 Adding Some Text To A Page There are five steps: 1. Create a new Element 2. Create new Text 3. Append the new Text to the new Element 4. Find an existing Element 5. Append the new Element to the existing Element
  • 9. 9 1. Create New Element Node Let us, say create a new <p> tag (element) so that we can attach some text to it For convenience, we can put the new object into a variable var newNode; newNode = document.createElement(“p”)
  • 10. 10 2. Create a Text Node Next, create a text node Again, for convenience, we can put the new text node into a variable var newText; newText = document.createTextNode(“Some text.”)
  • 11. 11 3. Attach the New Text Node to the New Element To put the text into the page, we have to attach the text node to the new HTML element: newNode.appendChild(newText);
  • 12. 12 4.Find an Existing Element The new element with our text node attached to it is still floating around in a Javascript world. We need to find an existing element so that we can attach it For convenience, we shall put this existing element into a variable var docElement; docElement = document.getElementById(“thisLocation”);
  • 13. 13 5. Append the New Element to the Existing Element To insert our text into the page, we now have to append the new element to the existing element docElement.appendChild(newNode);
  • 14. 14 Putting the 5 Steps Together <head> <script language="javascript" type="text/javascript"> var myText; myText = "This is new text to be added to the page dynamically."; function addText(location) { var newNode; var newText; var docElement; newNode = document.createElement("p"); newText = document.createTextNode(myText); newNode.appendChild(newText); docElement = document.getElementById(location); docElement.appendChild(newNode); }</script> </head> <body> <p><a href="#" onclick="addText('thisLocation');">Click to add new text to the page</a></p> <p id="thisLocation">New text will appear below here</p> <p>Some further text in the page</p> </body>
  • 15. 15 Attribute Nodes  We can get at the attributes of an element through attribute nodes  Attribute nodes, like text nodes are always contained in element nodes  We shall look at methods:  getAttribute()  setAttribute()
  • 16. 16 Getting Attribute Nodes  Hands On  Create a file JavascriptDOM.html  Add this code to alert the attribute of an element: function dispAttribs() { var messg; attribs = new Array; attribs = document.getElementsByTagName("p"); for (i = 0; i < attribs.length; i++) { messg = attribs[i].getAttribute("className"); alert(messg); } }  Add this to the bottom of the body: <p onclick="dispAttribs();">Click here to see class attributes</p>  Try this in Firefox  Point to consider: why is this attribute called ‘className’?
  • 17. 17 Setting Attribute Nodes  Hands On  Create the file JavascriptDOM.html  Add this code to change the attribute of an element: function chngAttribs() { var messg; attribs = new Array; attribs = document.getElementsByTagName("p"); for (i = 0; i < attribs.length; i++) { attribs[i].setAttribute("className","jazz"); } }  Add this to the bottom of the body: <p onclick="chngAttribs();">Click here to change class attributes</p>
  • 18. 18 User inserts and removes text  Hands On  Crate file JavascriptDOM.html  Place code in this page so that:  When the user mouseovers on an image, the relevant text appears  When the user mouseouts on an image, the text disappears
  • 19. Removing a node from the page19 function slideClick() { var bullets = document.getElementsByTagName("li"); for (var i = 0; i < bullets.length; i++) { if (bullets[i].innerHTML.indexOf("children") >= 0) { bullets[i].remove(); } } } JS  each DOM object has a removeChild method to remove its children from the page  Prototype adds a remove method for a node to remove itself