Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Overview
The Document Object Model (DOM) is an API that
allows programs to interact with HTML (or XML)
documents
DOM Introduction
Example: Rollover effect
Cursor not over image
DOM Introduction
DOM Introduction
Import
JavaScript
code
DOM Introduction
DOM Introduction
Calls to JavaScript
show() function when
mouse moves over/away
from image
DOM Introduction
DOM Introduction
DOM Introduction
DOM method returning Object
DOM Introduction
Returns instance
of Element
(DOM-defined
host object)
representing
HTML element
with given id
DOM Introduction
Some properties of
Element instance
correspond
to attributes of
HTML element
DOM Introduction
DOM Introduction
DOM Introduction
Ex: onmouseover
Name of attribute is on followed by event name
Change
background color
of element
containing cursor
Ex: color
color
Ex: background-color
backgroundColor
Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jacksons slides
CSS property
name
(unmodified)
Empty string
or
important
Document Tree
Recall that HTML document elements form
a tree structure, e.g.,
Ignore non-Elements
Recurse on
child nodes
Converting
null to Boolean
produces false
Swap nodes
if an li
element
follows
Modifying text.
Event type
Event handler
Definition
of event
handler
Event instance
Normally false
(more later)
click
mousedown
mouseup
mousemove
mouseover
mouseout
String uniquely
identifying this div
Add event
listener
Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jacksons slides
body
ol
li
a
Target
3. Bubbling event
handlers; ancestors
closest to target have
priority.
load
unload
focus
blur
Typical design:
When cursor
moves over
upper menu
a drop-down
appears
Drop-down
disappears
when cursor
leaves both
drop-down
and menu
Associated
drop-down is
a table
Document:
JavaScript addEventHandlers():
Target
event
handlers
Document:
JavaScript addEventListener():
Basic
processing:
change
visibility of
drop-down
Ignore
mouseout
event if
cursor is
remaining
over menu
item or
drop-down
(self or
descendant)
Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jacksons slides
Document:
JavaScript addEventListener():
Ignore
mouseout to
a descendant
Ex:
causes text in text field to be
selected and a select event to occur
Ex:
document.implementation(Core,
2.0) returns true if browser implements
all of DOM 2 Core module, false otherwise
Problem: what does false tell you?
DOM:
IE6:
Value assigned is a function Object (method)
rather than a String.
Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jacksons slides
DOM:
IE6:
Listener is called as a method
in IE6, so this is a reference
to button
DOM
approach
DOM
approach
IE6
approach
DOM
approach
IE6
approach
Basically an Array
of call arguments
Global object
created by IE6
Most type
values
(except
dblclick)
are copied
without
change
IE6 uses
a different
name for
target
Guy-Vincent Jourdan :: CSI 3140 :: based on Jeffrey C. Jacksons slides
Most mouse-event
properties are identical
appName
appVersion
userAgent