SlideShare a Scribd company logo
1 of 21
1
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
Document Object Model (DOM)
INFO/CSE 100, Spring 2006
Fluency in Information Technology
http://www.cs.washington.edu/100
2
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
References
• References
» JavaScript, The Definitive Guide
• by David Flanagan. Publisher O'Reilly
» W3C Document Object Model
• http://www.w3.org/DOM/
• http://www.w3.org/2003/02/06-dom-support.html
» Document Object Model in Mozilla
• http://www.mozilla.org/docs/dom/
3
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
What the heck is the DOM?
• Document Object Model
» Your web browser builds a model of the web
page (the document) that includes all the objects
in the page (tags, text, etc)
» All of the properties, methods, and events
available to the web developer for manipulating
and creating web pages are organized into
objects
» Those objects are accessible via scripting
languages in modern web browsers
<html>
<head>
<title>Sample DOM Document</title>
</head>
<body>
<h1>An HTML Document</h1>
<p>This is a <i>simple</i> document.
</body>
</html>
This is what the browser reads (sampleDOM.html).
This is what the browser displays on screen.
Document
<html>
<head>
<title>
"Sample DOM Document"
<body>
<h1> <p>
"An HTML Document"
"This is a"
"simple"
<i> "document"
Figure 17-1. The tree representation of an HTML document
Copied from JavaScript by Flanagan.
This is a drawing of the model that the
browser is working with for the page.
6
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
Why is this useful?
• Because we can access the model too!
» the model is made available to scripts running in
the browser, not just the browser itself
• A script can find things out about the state of the
page
• A script can change things in response to events,
including user requests
» We have already used this capability in the GUI
programming that we've done
7
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
Recall our simple GUI example
This GUI has several simple controls.
Two buttons to control the results
One text field to display the results
One pair of radio buttons to control the display
One button to reinitialize
http://www.cs.washington.edu/education/courses/100/04au/slides/16-dom/gui.html
8
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
setResults(resultString)
the highlighted script above makes
reference to several objects in the
document object model
<script type="text/javascript">
function setResults(resultString) {
var tempString = resultString;
if (document.getElementById("radioLC").checked) {
tempString = tempString.toLowerCase();
} else if (document.getElementById("radioUC").checked) {
tempString = tempString.toUpperCase();
}
document.getElementById("resultField").value = tempString;
}
</script>
9
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
document.getElementById("radioLC").checked
• Reference to several nodes in the model of the page
that the browser constructed
• document
» The root of the tree is an object of type HTMLDocument
» Using the global variable document, we can access all the
nodes in the tree, as well as useful functions and other
global information
• title, referrer, domain, URL, body, images, links, forms, ...
• open, write, close, getElementById, ...
Some information from a document
<html>
<head>
<title>DOM Sample A</title>
</head>
<body>
Information about this document.<br>
<script type="text/javascript">
document.write("<br>Title: ",document.title);
document.write("<br>Referrer: ",document.referrer);
document.write("<br>Domain: ",document.domain);
document.write("<br>URL: ",document.URL);
</script>
</body>
</html>
11
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
document.getElementById("radioLC").checked
• getElementById("radioLC")
» This is a predefined function that makes use of
the id that can be defined for any element in the
page
» An id must be unique in the page, so only one
element is ever returned by this function
» The argument to getElementById specifies
which element is being requested
Some information about elements
<html>
<head>
<title>DOM Sample B</title>
<script type="text/javascript">
function showInfo() {
var element = document.getElementById("opener");
var buffer = element.id + " tag is " + element.tagName;
alert(buffer);
element = document.getElementById("actionItem");
buffer = element.id + " tag is " + element.tagName;
buffer += ", type is "+element.type;
alert(buffer);
}
</script>
</head>
<body>
<p id="opener">The id attribute is very helpful.</p>
<p id="closer">This is the closing paragraph.</p>
<form>
<button id="actionItem" type="button" onclick="showInfo()">Show Info</button>
</form>
</body>
</html>
14
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
document.getElementById("radioLC").checked
• checked
» This is a particular property of the node we are
looking at, in this case, a radio button
» Each type of node has its own set of properties
• for radio button: checked, name, ...
• refer to the HTML DOM for specifics for each
element type
» Some properties can be both read and set
Some specific properties
<head>
<title>Simple Sample GUI</title>
<script type="text/javascript">
function setResults(resultString) {
var tempString = resultString;
if (document.getElementById("radioLC").checked) {
tempString = tempString.toLowerCase();
} else if (document.getElementById("radioUC").checked) {
tempString = tempString.toUpperCase();
}
document.getElementById("resultField").value = tempString;
}
</script>
</head>
17
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
Just the tip of the DOM
• The HTML Document Object Model is a standard
for structuring data on a web page
» The field is advancing rapidly as people recognize the
benefits of standardized structure and access
» The DOM is steadily improving to cover general purpose
data structuring requirements
• XML (Extendible Markup Language) also uses the
Core DOM to specify its structured data
» similar to HTML but more carefully defined
18
The
Information
School
of
the
University
of
Washington
7/25/2023 fit100-16-dom © 2006 University of Washington
Getting vs. Setting
var oldvalue = document.getElementById("resultField").value;
document.getElementById("resultField").value = "new value";
<html>
<head>
<title>DOM Sample C</title>
<script type="text/javascript">
var switchCount = 0;
var adjectives = ["simple","complex","fascinating","unique"];
function switcher() {
switchCount = (switchCount + 1) % adjectives.length;
var italicNode = document.getElementById("adjPhrase");
italicNode.firstChild.nodeValue = adjectives[switchCount];
}
</script>
</head>
<body>
<h1>An HTML Document</h1>
<p>This is a <i id="adjPhrase">simple</i> document.
<form>
<button type="button" onclick="switcher()">switch</button>
</form>
</body>
</html>
This is what the browser reads (domC.html).
This is what the browser displays on screen.

More Related Content

Similar to fit100-16-dom.ppt

Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
Fermin Galan
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mohammad Shaker
 

Similar to fit100-16-dom.ppt (20)

Developing your first application using FI-WARE
Developing your first application using FI-WAREDeveloping your first application using FI-WARE
Developing your first application using FI-WARE
 
Yuihacku iitd-sumana
Yuihacku iitd-sumanaYuihacku iitd-sumana
Yuihacku iitd-sumana
 
J query training
J query trainingJ query training
J query training
 
Introduction to Html5
Introduction to Html5Introduction to Html5
Introduction to Html5
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
AngularJS On-Ramp
AngularJS On-RampAngularJS On-Ramp
AngularJS On-Ramp
 
Building Smart Workflows - Dan Diebolt
Building Smart Workflows - Dan DieboltBuilding Smart Workflows - Dan Diebolt
Building Smart Workflows - Dan Diebolt
 
Basics of Java Script (JS)
Basics of Java Script (JS)Basics of Java Script (JS)
Basics of Java Script (JS)
 
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
Internet and Web Technology (CLASS-8) [jQuery and JSON] | NIC/NIELIT Web Tech...
 
14_ HTML Con't.ppt
14_ HTML Con't.ppt14_ HTML Con't.ppt
14_ HTML Con't.ppt
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
Javascript 1
Javascript 1Javascript 1
Javascript 1
 
Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIs
 
JavaScript lesson 1.pptx
JavaScript lesson 1.pptxJavaScript lesson 1.pptx
JavaScript lesson 1.pptx
 
Modern JavaScript Programming
Modern JavaScript Programming Modern JavaScript Programming
Modern JavaScript Programming
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
 

More from ssuseraf60311 (7)

String-Matching Algorithms Advance algorithm
String-Matching  Algorithms Advance algorithmString-Matching  Algorithms Advance algorithm
String-Matching Algorithms Advance algorithm
 
Graph coloring with back tracking aoa.ppt
Graph coloring with back tracking aoa.pptGraph coloring with back tracking aoa.ppt
Graph coloring with back tracking aoa.ppt
 
3526192.ppt
3526192.ppt3526192.ppt
3526192.ppt
 
8259731.ppt
8259731.ppt8259731.ppt
8259731.ppt
 
6065165.ppt
6065165.ppt6065165.ppt
6065165.ppt
 
application of http.pptx
application of http.pptxapplication of http.pptx
application of http.pptx
 
Working of web browser.pptx
Working of web browser.pptxWorking of web browser.pptx
Working of web browser.pptx
 

Recently uploaded

在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 

Recently uploaded (20)

2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 

fit100-16-dom.ppt

  • 1. 1 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington Document Object Model (DOM) INFO/CSE 100, Spring 2006 Fluency in Information Technology http://www.cs.washington.edu/100
  • 2. 2 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington References • References » JavaScript, The Definitive Guide • by David Flanagan. Publisher O'Reilly » W3C Document Object Model • http://www.w3.org/DOM/ • http://www.w3.org/2003/02/06-dom-support.html » Document Object Model in Mozilla • http://www.mozilla.org/docs/dom/
  • 3. 3 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington What the heck is the DOM? • Document Object Model » Your web browser builds a model of the web page (the document) that includes all the objects in the page (tags, text, etc) » All of the properties, methods, and events available to the web developer for manipulating and creating web pages are organized into objects » Those objects are accessible via scripting languages in modern web browsers
  • 4. <html> <head> <title>Sample DOM Document</title> </head> <body> <h1>An HTML Document</h1> <p>This is a <i>simple</i> document. </body> </html> This is what the browser reads (sampleDOM.html). This is what the browser displays on screen.
  • 5. Document <html> <head> <title> "Sample DOM Document" <body> <h1> <p> "An HTML Document" "This is a" "simple" <i> "document" Figure 17-1. The tree representation of an HTML document Copied from JavaScript by Flanagan. This is a drawing of the model that the browser is working with for the page.
  • 6. 6 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington Why is this useful? • Because we can access the model too! » the model is made available to scripts running in the browser, not just the browser itself • A script can find things out about the state of the page • A script can change things in response to events, including user requests » We have already used this capability in the GUI programming that we've done
  • 7. 7 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington Recall our simple GUI example This GUI has several simple controls. Two buttons to control the results One text field to display the results One pair of radio buttons to control the display One button to reinitialize http://www.cs.washington.edu/education/courses/100/04au/slides/16-dom/gui.html
  • 8. 8 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington setResults(resultString) the highlighted script above makes reference to several objects in the document object model <script type="text/javascript"> function setResults(resultString) { var tempString = resultString; if (document.getElementById("radioLC").checked) { tempString = tempString.toLowerCase(); } else if (document.getElementById("radioUC").checked) { tempString = tempString.toUpperCase(); } document.getElementById("resultField").value = tempString; } </script>
  • 9. 9 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington document.getElementById("radioLC").checked • Reference to several nodes in the model of the page that the browser constructed • document » The root of the tree is an object of type HTMLDocument » Using the global variable document, we can access all the nodes in the tree, as well as useful functions and other global information • title, referrer, domain, URL, body, images, links, forms, ... • open, write, close, getElementById, ...
  • 10. Some information from a document <html> <head> <title>DOM Sample A</title> </head> <body> Information about this document.<br> <script type="text/javascript"> document.write("<br>Title: ",document.title); document.write("<br>Referrer: ",document.referrer); document.write("<br>Domain: ",document.domain); document.write("<br>URL: ",document.URL); </script> </body> </html>
  • 11. 11 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington document.getElementById("radioLC").checked • getElementById("radioLC") » This is a predefined function that makes use of the id that can be defined for any element in the page » An id must be unique in the page, so only one element is ever returned by this function » The argument to getElementById specifies which element is being requested
  • 12. Some information about elements <html> <head> <title>DOM Sample B</title> <script type="text/javascript"> function showInfo() { var element = document.getElementById("opener"); var buffer = element.id + " tag is " + element.tagName; alert(buffer); element = document.getElementById("actionItem"); buffer = element.id + " tag is " + element.tagName; buffer += ", type is "+element.type; alert(buffer); } </script> </head> <body> <p id="opener">The id attribute is very helpful.</p> <p id="closer">This is the closing paragraph.</p> <form> <button id="actionItem" type="button" onclick="showInfo()">Show Info</button> </form> </body> </html>
  • 13.
  • 14. 14 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington document.getElementById("radioLC").checked • checked » This is a particular property of the node we are looking at, in this case, a radio button » Each type of node has its own set of properties • for radio button: checked, name, ... • refer to the HTML DOM for specifics for each element type » Some properties can be both read and set
  • 15. Some specific properties <head> <title>Simple Sample GUI</title> <script type="text/javascript"> function setResults(resultString) { var tempString = resultString; if (document.getElementById("radioLC").checked) { tempString = tempString.toLowerCase(); } else if (document.getElementById("radioUC").checked) { tempString = tempString.toUpperCase(); } document.getElementById("resultField").value = tempString; } </script> </head>
  • 16.
  • 17. 17 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington Just the tip of the DOM • The HTML Document Object Model is a standard for structuring data on a web page » The field is advancing rapidly as people recognize the benefits of standardized structure and access » The DOM is steadily improving to cover general purpose data structuring requirements • XML (Extendible Markup Language) also uses the Core DOM to specify its structured data » similar to HTML but more carefully defined
  • 18. 18 The Information School of the University of Washington 7/25/2023 fit100-16-dom © 2006 University of Washington Getting vs. Setting var oldvalue = document.getElementById("resultField").value; document.getElementById("resultField").value = "new value";
  • 19.
  • 20. <html> <head> <title>DOM Sample C</title> <script type="text/javascript"> var switchCount = 0; var adjectives = ["simple","complex","fascinating","unique"]; function switcher() { switchCount = (switchCount + 1) % adjectives.length; var italicNode = document.getElementById("adjPhrase"); italicNode.firstChild.nodeValue = adjectives[switchCount]; } </script> </head> <body> <h1>An HTML Document</h1> <p>This is a <i id="adjPhrase">simple</i> document. <form> <button type="button" onclick="switcher()">switch</button> </form> </body> </html> This is what the browser reads (domC.html).
  • 21. This is what the browser displays on screen.