SlideShare une entreprise Scribd logo
1  sur  16
INFT11/71-132
       Web Applications


Document Object Model
        Dr Michael Rees
  School of Information Technology

        mrees@bond.edu.au
HTML Document Object Model

• The DOM is an abstract model that defines the interface
  between HTML documents and application programs—an API

• Documents in the DOM have a tree structure (see Firebug/IE8)

• A language that supports the DOM must have a binding to the
  DOM constructs

• In the JavaScript binding, HTML elements are represented as
  objects

• Element attributes are represented as properties:
          – <input type = "text" name = "address"> is represented as
            an object with two properties, type and name, with the
            values ―text" and "address"
© 2009 Michael Rees                   Web Applications                 2
HTML Document Object Model

• A standard object model for HTML
• A standard applications programming interface (API) for
  HTML
• Platform- and language-independent
• A W3C standard
• The HTML DOM defines the objects and properties of all
  HTML elements, the methods (interface) to access them,
  and the events generated
• In other words: a standard for how to get, change, add, or
  delete HTML elements
© 2009 Michael Rees                Web Applications         3
JavaScript Execution Environment

• DOM window object represents the browser window
  which displays documents

• All global variables are properties of window

• Implicitly defined window properties:
   – document displays page content
   – frames: an array of frame object




© 2009 Michael Rees                  Web Applications    4
Document Properties

• forms: an array of references to the forms of the
  document, and each form
   – elements array, which references the form’s elements

• anchors array of named link positions

• links array of <a> tags

• images array of <img> tags




© 2009 Michael Rees                 Web Applications        5
DOM Nodes
      <html>                        •   The entire document is a document node
       <head>                       •   Every HTML element is an element node
        <title>My title</title>     •   The text in the HTML elements are text nodes
       </head>                      •   Every HTML attribute is an attribute node
       <body>                       •   Comments are comment nodes
        <h1>My header</h1>
        <a href="url">My link</a>
       </body>
      </html>




© 2009 Michael Rees                          Web Applications                          6
Parents, Children, Siblings
• In a node tree, the top
  node is called the root
• Every node, except the
  root, has exactly one
  parent node
• A node can have any
  number of children
• A leaf is a node with no
  children
• Siblings are nodes with the
  same parent
© 2009 Michael Rees                   Web Applications   7
DOM Node Properties

Some of the common properties:

• x.innerHTML - the text value of x

• x.nodeName - the name of x

• x.nodeValue - the value of x

• x.parentNode - the parent node of x

• x.childNodes - the child nodes of x

• x.attributes - the attributes nodes of x


© 2009 Michael Rees                 Web Applications   8
DOM Methods

Some DOM methods:

• document.getElementById(id) - get the element with a
  specified id

• document.getElementsByTagName(name) - get all
  elements with a specified tag name

• x.appendChild(node) - insert a child node to x

• x.removeChild(node) - remove a child node from x




© 2009 Michael Rees                 Web Applications     9
Example

      <body>

       <p id="intro">Hello World!</p>

       <script type="text/javascript">


       var introNode = document.getElementById("intro");
       document.write(introNode.firstChild.nodeValue);


       </script>
       <body>
© 2009 Michael Rees               Web Applications         10
Change Node Value

<body>

<p id="p1">Hello World!</p>

<script type="text/javascript">

document.getElementById("p1").innerHTML = "New text!";

</script>

</body>




© 2009 Michael Rees                Web Applications      11
Functions and Events Example
<head>
<script type="text/javascript">
function Change () {
    document.getElementById("p1").innerHTML = "New text!";
    document.body.style.backgroundColor = "lavender";
    document.getElementById("p1").style.color = ―red";
    document.getElementById("p1").style.fontFamily =― Arial";
}
</script>
</head>
<body>
<h1 id="p1">Hello world!</h1>
<input type="button" onclick="Change()" value="Change" />
</body>

© 2009 Michael Rees                                Web Applications   12
Events and Event Handling
• An event is a notification that an action has occurred, either with the
  browser or performed by the user
• When the event occurs an event object is created
• An event handler is a script that is executed in response to the appearance
  of an event
• The process of connecting an event handler to an event is called registration
• Event examples:
   – A mouse click
   – A web page or an image loading completely
   – Mousing over a hot spot on the web page
   – Selecting an input box in an HTML form
   – Submitting an HTML form
   – A keystroke



© 2009 Michael Rees                     Web Applications                        13
Events and Tag Attributes
Event                    Tag Attribute      Event                Tag Attribute
blur                     onlblur            mousedown            onmousedown
change                   onchange           mousemove            onmousemove
click                    onclick            mouseout             onmouseout
dblclick                 ondblclick         mouseover            onmouseover
focus                    onfocus            reset                onreset
keydown                  onkeydown          select               onselect
keypress                 onkeypress         submit               onsubmit
keyup                    onkeyup            unload               onunload
load                     onload




                                               W3Schools Event Reference
© 2009 Michael Rees                      Web Applications                      14
DOM 2 Event Model

• So far the DOM 0 and 1 event models were described

• DOM 2 Event Model:
   – event handlers (listeners) associated with nodes
   – multiple handlers for same event allowed on single node
   – event object created at the target node in the DOM
   – capture phase starts at root and descends to target
     triggering event handlers on the way
   – any listener on target node triggered
   – bubble phase works way up tree to root again triggering
     handlers on the way
   – any handler can stop further propagation

© 2009 Michael Rees                Web Applications            15
Reading

• Read Chapter 5 of the textbook




© 2009 Michael Rees             Web Applications   16

Contenu connexe

Tendances

Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Document object model
Document object modelDocument object model
Document object modelAmit kumar
 
The Document Object Model
The Document Object ModelThe Document Object Model
The Document Object ModelKhou Suylong
 
Understanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoUnderstanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoDamalie Wasukira
 
13. session 13 introduction to dhtml
13. session 13   introduction to dhtml13. session 13   introduction to dhtml
13. session 13 introduction to dhtmlPhúc Đỗ
 
INTRODUCTION TO DOM AND DOM TREE
INTRODUCTION TO DOM AND DOM TREEINTRODUCTION TO DOM AND DOM TREE
INTRODUCTION TO DOM AND DOM TREEsystematiclab
 
Web Design & Development Courses in Pune |Web Development Classes in Pune | ...
Web Design & Development Courses  in Pune |Web Development Classes in Pune | ...Web Design & Development Courses  in Pune |Web Development Classes in Pune | ...
Web Design & Development Courses in Pune |Web Development Classes in Pune | ...abeda786
 
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)Beat Signer
 
Web Design & Development Courses in Pune| 3DOT Technologies
Web Design & Development Courses  in Pune| 3DOT TechnologiesWeb Design & Development Courses  in Pune| 3DOT Technologies
Web Design & Development Courses in Pune| 3DOT Technologiesabeda786
 
Laura Dawson: An Intro to StartWithXML
Laura Dawson: An Intro to StartWithXMLLaura Dawson: An Intro to StartWithXML
Laura Dawson: An Intro to StartWithXMLStartWithXMLLondon
 
3 dot technologies by deepak modi
3 dot technologies by deepak modi3 dot technologies by deepak modi
3 dot technologies by deepak modiDeepak Modi
 

Tendances (20)

Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Dhtml ppt (2)
Dhtml ppt (2)Dhtml ppt (2)
Dhtml ppt (2)
 
Introduction to DOM
Introduction to DOMIntroduction to DOM
Introduction to DOM
 
Document object model
Document object modelDocument object model
Document object model
 
The Document Object Model
The Document Object ModelThe Document Object Model
The Document Object Model
 
Dhtml
DhtmlDhtml
Dhtml
 
Understanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoUnderstanding the dom by Benedict Ayiko
Understanding the dom by Benedict Ayiko
 
Unit 2 dhtml
Unit 2 dhtmlUnit 2 dhtml
Unit 2 dhtml
 
Introduction to the DOM
Introduction to the DOMIntroduction to the DOM
Introduction to the DOM
 
13. session 13 introduction to dhtml
13. session 13   introduction to dhtml13. session 13   introduction to dhtml
13. session 13 introduction to dhtml
 
INTRODUCTION TO DOM AND DOM TREE
INTRODUCTION TO DOM AND DOM TREEINTRODUCTION TO DOM AND DOM TREE
INTRODUCTION TO DOM AND DOM TREE
 
Dynamic HTML (DHTML)
Dynamic HTML (DHTML)Dynamic HTML (DHTML)
Dynamic HTML (DHTML)
 
Web Design & Development Courses in Pune |Web Development Classes in Pune | ...
Web Design & Development Courses  in Pune |Web Development Classes in Pune | ...Web Design & Development Courses  in Pune |Web Development Classes in Pune | ...
Web Design & Development Courses in Pune |Web Development Classes in Pune | ...
 
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
 
Web Design & Development Courses in Pune| 3DOT Technologies
Web Design & Development Courses  in Pune| 3DOT TechnologiesWeb Design & Development Courses  in Pune| 3DOT Technologies
Web Design & Development Courses in Pune| 3DOT Technologies
 
Laura Dawson: An Intro to StartWithXML
Laura Dawson: An Intro to StartWithXMLLaura Dawson: An Intro to StartWithXML
Laura Dawson: An Intro to StartWithXML
 
Xml applications
Xml applicationsXml applications
Xml applications
 
Dhtml
DhtmlDhtml
Dhtml
 
Dhtml
DhtmlDhtml
Dhtml
 
3 dot technologies by deepak modi
3 dot technologies by deepak modi3 dot technologies by deepak modi
3 dot technologies by deepak modi
 

Similaire à INFT132 093 07 Document Object Model

Basic web security model
Basic web security modelBasic web security model
Basic web security modelG Prachi
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & eventBorey Lim
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)BOSS Webtech
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxkarthiksmart21
 
INFT132 093 04 HTML and XHTML
INFT132 093 04 HTML and XHTMLINFT132 093 04 HTML and XHTML
INFT132 093 04 HTML and XHTMLMichael Rees
 
Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)Julie Meloni
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignBradley Holt
 
Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1drudolph11
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web componentsMike North
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom eventBunlong Van
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy stepsprince Loffar
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven developmentGil Fink
 

Similaire à INFT132 093 07 Document Object Model (20)

Basic web security model
Basic web security modelBasic web security model
Basic web security model
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & event
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
JavaScript and DOM
JavaScript and DOMJavaScript and DOM
JavaScript and DOM
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
 
INFT132 093 04 HTML and XHTML
INFT132 093 04 HTML and XHTMLINFT132 093 04 HTML and XHTML
INFT132 093 04 HTML and XHTML
 
HTML_DOM
HTML_DOMHTML_DOM
HTML_DOM
 
Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
lect9
lect9lect9
lect9
 
lect9
lect9lect9
lect9
 
Part 7
Part 7Part 7
Part 7
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven Design
 
Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1Windows 8 DevUnleashed - Session 1
Windows 8 DevUnleashed - Session 1
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web components
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Web components
Web componentsWeb components
Web components
 
dmBridge & dmMonocle
dmBridge & dmMonocledmBridge & dmMonocle
dmBridge & dmMonocle
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 

Plus de Michael Rees

Activity 25 reflecting on openness
Activity 25 reflecting on opennessActivity 25 reflecting on openness
Activity 25 reflecting on opennessMichael Rees
 
Experiences with MOOCs: Challenges and Opportunities
Experiences with MOOCs: Challenges and OpportunitiesExperiences with MOOCs: Challenges and Opportunities
Experiences with MOOCs: Challenges and OpportunitiesMichael Rees
 
Messing with MOOCs
Messing with MOOCsMessing with MOOCs
Messing with MOOCsMichael Rees
 
Developing Inside the Cloud
Developing Inside the CloudDeveloping Inside the Cloud
Developing Inside the CloudMichael Rees
 
ABC Gold Coast Social Media Talk
ABC Gold Coast Social Media TalkABC Gold Coast Social Media Talk
ABC Gold Coast Social Media TalkMichael Rees
 
Virtualisation advances for teaching and research
Virtualisation advances for teaching and researchVirtualisation advances for teaching and research
Virtualisation advances for teaching and researchMichael Rees
 
Building Classroom Community
Building Classroom CommunityBuilding Classroom Community
Building Classroom CommunityMichael Rees
 
Teaching with Social Media
Teaching with Social MediaTeaching with Social Media
Teaching with Social MediaMichael Rees
 
Teaching with Social Media
Teaching with Social MediaTeaching with Social Media
Teaching with Social MediaMichael Rees
 
Cloud Apps Ascent - Snapshot
Cloud Apps Ascent - SnapshotCloud Apps Ascent - Snapshot
Cloud Apps Ascent - SnapshotMichael Rees
 
Cloud Apps Survival Of The Fittest
Cloud Apps   Survival Of The FittestCloud Apps   Survival Of The Fittest
Cloud Apps Survival Of The FittestMichael Rees
 
INFT132 093 05 Cascading Style Sheets
INFT132 093 05 Cascading Style SheetsINFT132 093 05 Cascading Style Sheets
INFT132 093 05 Cascading Style SheetsMichael Rees
 
INFT132 093 03 Web Concepts
INFT132 093 03 Web ConceptsINFT132 093 03 Web Concepts
INFT132 093 03 Web ConceptsMichael Rees
 
INFT132 093 02 Internet Concepts
INFT132 093 02 Internet ConceptsINFT132 093 02 Internet Concepts
INFT132 093 02 Internet ConceptsMichael Rees
 
Get Connected - Building a Social Media Roadmap
Get Connected - Building a Social Media RoadmapGet Connected - Building a Social Media Roadmap
Get Connected - Building a Social Media RoadmapMichael Rees
 
Favourite Cloud Apps
Favourite Cloud AppsFavourite Cloud Apps
Favourite Cloud AppsMichael Rees
 
Screencasting to Enhance Teaching Materials
Screencasting to Enhance Teaching MaterialsScreencasting to Enhance Teaching Materials
Screencasting to Enhance Teaching MaterialsMichael Rees
 
QCEC2009 Virtual IT Teaching Laboratory
QCEC2009 Virtual IT Teaching LaboratoryQCEC2009 Virtual IT Teaching Laboratory
QCEC2009 Virtual IT Teaching LaboratoryMichael Rees
 
Screencasting At Bond
Screencasting At BondScreencasting At Bond
Screencasting At BondMichael Rees
 

Plus de Michael Rees (20)

Activity 25 reflecting on openness
Activity 25 reflecting on opennessActivity 25 reflecting on openness
Activity 25 reflecting on openness
 
Experiences with MOOCs: Challenges and Opportunities
Experiences with MOOCs: Challenges and OpportunitiesExperiences with MOOCs: Challenges and Opportunities
Experiences with MOOCs: Challenges and Opportunities
 
MOOCs march on
MOOCs march onMOOCs march on
MOOCs march on
 
Messing with MOOCs
Messing with MOOCsMessing with MOOCs
Messing with MOOCs
 
Developing Inside the Cloud
Developing Inside the CloudDeveloping Inside the Cloud
Developing Inside the Cloud
 
ABC Gold Coast Social Media Talk
ABC Gold Coast Social Media TalkABC Gold Coast Social Media Talk
ABC Gold Coast Social Media Talk
 
Virtualisation advances for teaching and research
Virtualisation advances for teaching and researchVirtualisation advances for teaching and research
Virtualisation advances for teaching and research
 
Building Classroom Community
Building Classroom CommunityBuilding Classroom Community
Building Classroom Community
 
Teaching with Social Media
Teaching with Social MediaTeaching with Social Media
Teaching with Social Media
 
Teaching with Social Media
Teaching with Social MediaTeaching with Social Media
Teaching with Social Media
 
Cloud Apps Ascent - Snapshot
Cloud Apps Ascent - SnapshotCloud Apps Ascent - Snapshot
Cloud Apps Ascent - Snapshot
 
Cloud Apps Survival Of The Fittest
Cloud Apps   Survival Of The FittestCloud Apps   Survival Of The Fittest
Cloud Apps Survival Of The Fittest
 
INFT132 093 05 Cascading Style Sheets
INFT132 093 05 Cascading Style SheetsINFT132 093 05 Cascading Style Sheets
INFT132 093 05 Cascading Style Sheets
 
INFT132 093 03 Web Concepts
INFT132 093 03 Web ConceptsINFT132 093 03 Web Concepts
INFT132 093 03 Web Concepts
 
INFT132 093 02 Internet Concepts
INFT132 093 02 Internet ConceptsINFT132 093 02 Internet Concepts
INFT132 093 02 Internet Concepts
 
Get Connected - Building a Social Media Roadmap
Get Connected - Building a Social Media RoadmapGet Connected - Building a Social Media Roadmap
Get Connected - Building a Social Media Roadmap
 
Favourite Cloud Apps
Favourite Cloud AppsFavourite Cloud Apps
Favourite Cloud Apps
 
Screencasting to Enhance Teaching Materials
Screencasting to Enhance Teaching MaterialsScreencasting to Enhance Teaching Materials
Screencasting to Enhance Teaching Materials
 
QCEC2009 Virtual IT Teaching Laboratory
QCEC2009 Virtual IT Teaching LaboratoryQCEC2009 Virtual IT Teaching Laboratory
QCEC2009 Virtual IT Teaching Laboratory
 
Screencasting At Bond
Screencasting At BondScreencasting At Bond
Screencasting At Bond
 

Dernier

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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Dernier (20)

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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

INFT132 093 07 Document Object Model

  • 1. INFT11/71-132 Web Applications Document Object Model Dr Michael Rees School of Information Technology mrees@bond.edu.au
  • 2. HTML Document Object Model • The DOM is an abstract model that defines the interface between HTML documents and application programs—an API • Documents in the DOM have a tree structure (see Firebug/IE8) • A language that supports the DOM must have a binding to the DOM constructs • In the JavaScript binding, HTML elements are represented as objects • Element attributes are represented as properties: – <input type = "text" name = "address"> is represented as an object with two properties, type and name, with the values ―text" and "address" © 2009 Michael Rees Web Applications 2
  • 3. HTML Document Object Model • A standard object model for HTML • A standard applications programming interface (API) for HTML • Platform- and language-independent • A W3C standard • The HTML DOM defines the objects and properties of all HTML elements, the methods (interface) to access them, and the events generated • In other words: a standard for how to get, change, add, or delete HTML elements © 2009 Michael Rees Web Applications 3
  • 4. JavaScript Execution Environment • DOM window object represents the browser window which displays documents • All global variables are properties of window • Implicitly defined window properties: – document displays page content – frames: an array of frame object © 2009 Michael Rees Web Applications 4
  • 5. Document Properties • forms: an array of references to the forms of the document, and each form – elements array, which references the form’s elements • anchors array of named link positions • links array of <a> tags • images array of <img> tags © 2009 Michael Rees Web Applications 5
  • 6. DOM Nodes <html> • The entire document is a document node <head> • Every HTML element is an element node <title>My title</title> • The text in the HTML elements are text nodes </head> • Every HTML attribute is an attribute node <body> • Comments are comment nodes <h1>My header</h1> <a href="url">My link</a> </body> </html> © 2009 Michael Rees Web Applications 6
  • 7. Parents, Children, Siblings • In a node tree, the top node is called the root • Every node, except the root, has exactly one parent node • A node can have any number of children • A leaf is a node with no children • Siblings are nodes with the same parent © 2009 Michael Rees Web Applications 7
  • 8. DOM Node Properties Some of the common properties: • x.innerHTML - the text value of x • x.nodeName - the name of x • x.nodeValue - the value of x • x.parentNode - the parent node of x • x.childNodes - the child nodes of x • x.attributes - the attributes nodes of x © 2009 Michael Rees Web Applications 8
  • 9. DOM Methods Some DOM methods: • document.getElementById(id) - get the element with a specified id • document.getElementsByTagName(name) - get all elements with a specified tag name • x.appendChild(node) - insert a child node to x • x.removeChild(node) - remove a child node from x © 2009 Michael Rees Web Applications 9
  • 10. Example <body> <p id="intro">Hello World!</p> <script type="text/javascript"> var introNode = document.getElementById("intro"); document.write(introNode.firstChild.nodeValue); </script> <body> © 2009 Michael Rees Web Applications 10
  • 11. Change Node Value <body> <p id="p1">Hello World!</p> <script type="text/javascript"> document.getElementById("p1").innerHTML = "New text!"; </script> </body> © 2009 Michael Rees Web Applications 11
  • 12. Functions and Events Example <head> <script type="text/javascript"> function Change () { document.getElementById("p1").innerHTML = "New text!"; document.body.style.backgroundColor = "lavender"; document.getElementById("p1").style.color = ―red"; document.getElementById("p1").style.fontFamily =― Arial"; } </script> </head> <body> <h1 id="p1">Hello world!</h1> <input type="button" onclick="Change()" value="Change" /> </body> © 2009 Michael Rees Web Applications 12
  • 13. Events and Event Handling • An event is a notification that an action has occurred, either with the browser or performed by the user • When the event occurs an event object is created • An event handler is a script that is executed in response to the appearance of an event • The process of connecting an event handler to an event is called registration • Event examples: – A mouse click – A web page or an image loading completely – Mousing over a hot spot on the web page – Selecting an input box in an HTML form – Submitting an HTML form – A keystroke © 2009 Michael Rees Web Applications 13
  • 14. Events and Tag Attributes Event Tag Attribute Event Tag Attribute blur onlblur mousedown onmousedown change onchange mousemove onmousemove click onclick mouseout onmouseout dblclick ondblclick mouseover onmouseover focus onfocus reset onreset keydown onkeydown select onselect keypress onkeypress submit onsubmit keyup onkeyup unload onunload load onload W3Schools Event Reference © 2009 Michael Rees Web Applications 14
  • 15. DOM 2 Event Model • So far the DOM 0 and 1 event models were described • DOM 2 Event Model: – event handlers (listeners) associated with nodes – multiple handlers for same event allowed on single node – event object created at the target node in the DOM – capture phase starts at root and descends to target triggering event handlers on the way – any listener on target node triggered – bubble phase works way up tree to root again triggering handlers on the way – any handler can stop further propagation © 2009 Michael Rees Web Applications 15
  • 16. Reading • Read Chapter 5 of the textbook © 2009 Michael Rees Web Applications 16