9.6. Alphabetical Object Reference
The a object reflects the a
element, regardless of whether the element is set up to be an anchor,
link, or both. Early versions of Navigator and Internet Explorer
treat this object only as a member of the links[]
and/or anchors[ ] arrays of a document. Starting
with IE 4 and Netscape 6, you can access the object through supported
element object reference syntax (e.g., the
document.all[] collection for IE or
document.getElementById( ) for IE 5 and later and
Netscape 6).
HTML Equivalent
<a>
Object Model Reference
[window.]document.links[i]
[window.]document.anchors[i]
[window.]document.getElementById("elementID")
Object-Specific Properties
charset
|
coords
|
dataFld
|
dataFormatAs
|
dataSrc
|
hash
|
host
|
hostname
|
href
|
hreflang
|
Methods
|
mimeType
|
name
|
nameProp
|
pathname
|
port
|
protocol
|
protocolLong
|
rev
|
search
|
shape
|
target
|
text
|
type
|
urn
|
|
|
|
|
|
Object-Specific Methods
None.
Object-Specific Event Handler Properties
Handler
|
NN
|
IE
|
DOM
|
onblur
|
n/a
|
4
|
n/a
|
onclick
|
2
|
3
|
2
|
ondblclick
|
4
|
4
|
n/a
|
onfocus
|
n/a
|
4
|
n/a
|
onhelp
|
n/a
|
4
|
n/a
|
onmousedown
|
4
|
4
|
2
|
onmousemove
|
6
|
4
|
2
|
onmouseout
|
3
|
4
|
2
|
onmouseover
|
2
|
3
|
2
|
onmouseup
|
4
|
4
|
2
|
Anchor-only a objects have no event handlers in
Navigator through Version 4.
Character encoding of the document's content.
Example
if (document.getElementById("myAnchor").charset == "csISO5427Cyrillic") {
// process for Cyrillic charset
}
Value
Case-insensitive alias from the character set registry (ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets).
Default
Determined by browser.
Defines the outline of an area to be associated with a particular
link or scripted action. This property is a member of the
a object, but really belongs to the
area object, which inherits the properties of the
a object. Coordinate values are entered as a
comma-delimited list. If hotspots of two areas should overlap, the
area that is defined earlier in the code takes precedence.
Example
document.getElementById("mapArea2").coords = "25, 5, 50, 70";
Value
Each coordinate is a length value, but the number of coordinates and
their order depend on the shape specified by the
shape attribute, which may optionally be
associated with the element. For shape="rect",
there are four coordinates (left, top, right, bottom); for
shape="circle" there are three coordinates
(center-x, center-y, radius); for shape="poly"
there are two coordinate values for each point that defines the shape
of the polygon.
Default
None.
dataFld | NN n/a IE 4 DOM n/a |
Used with IE data binding to associate a remote data source column
value in lieu of an href attribute for a link. The
datasrc attribute must also be set for the
element. Setting both the dataFld and
dataSrc properties to empty strings breaks the
binding between element and data source. Works only with text file
data sources in IE 5/Mac.
Example
document.getElementById("hotlink").dataFld = "linkURL";
Value
Case-sensitive identifier of the data source column.
Default
None.
dataFormatAs | NN n/a IE 4 DOM n/a |
Used with IE data binding, this property advises the browser whether
the source material arriving from the data source is to be treated as
plain text or as tagged HTML.
Example
document.getElementById("hotlink").dataFormatAs = "HTML";
Value
IE recognizes two possible settings: text |
html.
Default
text
dataSrc | NN n/a IE 4 DOM n/a |
Used with IE data binding to specify the ID of the
page's object element that loads
the data source object for remote data access. Content from the data
source to be inserted into the a element text is
specified via the datafld property. Setting both
the dataFld and dataSrc
properties to empty strings breaks the binding between element and
data source. Works only with text file data sources in IE 5/Mac.
Example
document.all.hotlink.dataSrc = "#DBSRC3";
Value
Case-sensitive identifier of the data source.
Default
None.
Provides that portion of the href
attribute's URL following the #
symbol, referring to an anchor location in a document. Do not include
the # symbol when setting the property.
Example
document.getElementById("myLink").hash = "section3";
document.links[2].hash = "section3";
Value
String.
Default
None.
This is the combination of the hostname and port (if any) of the
server of the destination document for the link. If the port is
explicitly part of the URL, the hostname and port are separated by a
colon, just as they are in the URL. If the port number is not
specified in an HTTP URL for IE, it automatically returns the
default, port 80.
Example
document.getElementById("myLink").host = "www.megacorp.com:80";
document.links[2].host = "www.megacorp.com:80";
Value
String of hostname optionally followed by a colon and port number.
Default
Depends on server.
This is the hostname of the server (i.e., a
"two-dot" address consisting of
server name and domain) of the destination document for the link. The
hostname property does not include the port
number.
Example
document.getElementById("myLink").hostname = "www.megacorp.com";
document.links[2].hostname = "www.megacorp.com";
Value
String of hostname (server and domain).
Default
Depends on server.
Provides the URL specified by the element's
href attribute.
Example
document.getElementById("myLink").href = "http://www.megacorp.com";
document.links[2].href = "http://www.megacorp.com";
Value
String of complete or relative URL.
Default
None.
Provides the language code of the content at the destination of a
link. Requires that the href attribute or property
also be set.
Example
document.getElementById("myLink").hreflang = "DE";
Value
Case-insensitive language code.
Default
None.
Methods | NN n/a IE 4 DOM n/a |
Provides an advisory attribute about the functionality of the
destination of a link. A browser could use this information to
display special colors or images for the element content based on
what the destination does for the user, but Internet Explorer does
not appear to do anything with this information.
Example
document.links[1].Methods = "post";
Value
Any valid HTTP method as a string.
Default
None.
mimeType | NN n/a IE 4 DOM n/a |
Returns a plain-language version of the MIME type of the destination
document at the other end of the link specified by the
href attribute. You could use this information to
set the cursor type during a mouse rollover. Don't
confuse this property with the
navigator.mimeTypes[] array and individual
mimeType objects that Netscape Navigator refers
to. This is not available in IE 4/Macintosh.
Example
if (document.getElementById("myLink").mimeType == "GIF Image") {
...
}
Value
A plain-language reference to the MIME type as a string.
Default
None.
This is the identifier associated with an element that turns it into
an anchor. You can also use the name as part of the object reference.
Example
if (document.links[12].name == "section3") {
...
}
Value
Case-sensitive identifier that follows the rules of identifier
naming: it may contain no whitespace, cannot begin with a numeral,
and should avoid punctuation except for the underscore character.
Default
None.
nameProp | NN n/a IE 4 DOM n/a |
Returns just the filename, rather than the full URL, of the
href attribute set for the element. Not available
in IE 4/Macintosh.
Example
if (document.getElementById("myLink").nameProp == "logo2.gif") {
...
}
Value
String.
Default
None.
Provides the pathname component of the URL assigned to the
element's href attribute. This
consists of all URL information following the last character of the
domain name, including the initial forward slash symbol.
Example
document.getElementById("myLink").pathname = "/images/logoHiRes.gif";
document.links[2].pathname = "/images/logoHiRes.gif";
Value
String.
Default
None.
Provides the port component of the URL assigned to the
element's href attribute. This
consists of all URL information following the colon after the last
character of the domain name. The colon is not part of the
port property value.
Example
document.getElementById("myLink").port = "80";
document.links[2].port = "80";
Value
String (a numeric value as string).
Default
None.
Indicates the protocol component of the URL assigned to the
element's href attribute. This
consists of all URL information up to and including the first colon
of a URL. Typical values are: "http:",
"file:", "ftp:", and
"mailto:".
Example
document.getElementById("secureLink").protocol = "https:";
Value
String.
Default
None.
protocolLong | NN n/a IE 4 DOM n/a |
Provides a verbose description of the protocol implied by the URL of
the href attribute or href
property. Not supported in IE 4/Macintosh, and appears to be
deprecated .
Example
if (document.getElementById("myLink").protocolLong ==
"HyperText Transfer Protocol") {
// statements for treating document as server file
}
Value
String.
Default
None
Defines the relationship between the current element and the
destination of the link. Also known as a forward
link, not to be confused in any way with the destination
document whose address is defined by the href
attribute. Mainstream browsers do not take advantage of this
attribute for the a element, but you can treat the
attribute as a kind of parameter to be checked and/or modified under
script control. See the discussion of the a
element's rel attribute in Chapter 8 for a glimpse of how this property may
be used in the future.
Value
Case-insensitive, space-delimited list of HTML 4.0 standard link
types (as a single string) applicable to the element. Sanctioned link
types are:
alternate
|
appendix
|
bookmark
|
chapter
|
contents
|
copyright
|
glossary
|
help
|
index
|
next
|
prev
|
section
|
start
|
stylesheet
|
subsection
|
Default
None.
Defines the relationship between the current element and the
destination of the link. Also known as a reverse
link. This property is not exploited yet in mainstream
browsers, but you can treat the attribute as a kind of parameter to
be checked and/or modified under script control. See the discussion
of the a element's
rev attribute in Chapter 8 for a glimpse of how this property may
be used in the future.
Value
Case-insensitive, space-delimited list of HTML 4.0 standard link
types (as a single string) applicable to the element. See the
rel property for sanctioned link types.
Default
None.
Provides the URL-encoded portion of a URL assigned to the
href attribute that begins with the
? symbol. A document that is served up as the
result of the search also may have the search portion available as
part of the window.location property. You can
modify this property with a script. Doing so sends the URL and search
criteria to the server. You must know the format of data (usually
name/value pairs) expected by the server to perform this properly.
Example
document.getElementById("searchLink").search="?p=Tony+Blair&d=y&g=0&s=a&w=s&m=25";
document.links[1].search="?p=Tony+Blair&d=y&g=0&s=a&w=s&m=25";
Value
String starting with the ? symbol.
Default
None.
Indicates the shape of a server-side image map area, with coordinates
that are specified with the COORDS attribute.
Intended for use by the area object, which
inherits the properties of the a object.
Example
document.getElementById("myLink").shape = "circle";
Value
Case-insensitive shape constant as string: default
| rect |
rectangle |
circle |
poly | polygon.
Default
rect
Provides the name of the window or frame that is to receive content
as the result of navigating to a link. Such names are assigned to
frames by the frame element's
name attribute; for subwindows, the name is
assigned via the second parameter of the window.open(
) method. If you need the services of a
target attribute to open a linked page in a blank
browser window and you also need the HTML to validate under strict
HTML or XHTML DTDs (see Chapter 1), you can omit
the target attribute in the code, but you must
assign a value to the a element's
target property by script after the page loads.
Example
document.getElementById("homeLink").target = "_top";
document.links[3].target = "_top";
Value
String value of the window or frame name, or any of the following
constants (as a string): _parent |
_self | _top |
_blank. The _parent value
targets the frameset to which the current document belongs; the
_self value targets the current window; the
_top value targets the main browser window,
thereby eliminating all frames; and the _blank
value creates a new window of default size.
Default
None.
Returns the text between the a
element's start and end tags. This property
pre-dates the W3C DOM and should be used only if needed for Navigator
4.
Value
String value.
Default
None.
This is the MIME type of the destination document at the other end of
the link specified by the href attribute. A
browser might use this information to assist in preparing support for
a resource requiring a multimedia player or plugin.
Example
if (document.getElementById("myLink").type == "image/jpeg") {
...
}
Value
Case-insensitive MIME type. A catalog of registered MIME types is
available from ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/.
Default
None.
Indicates a Uniform Resource Name (URN) version of the destination
document specified in the href attribute. This
attribute is intended to offer support in the future for the URN
format of URI, an evolving recommendation under discussion at the
IETF (see RFC 2141). Although supported in IE, this attribute does
not take the place of the href attribute.
Example
document.getElementById("link3").urn = "http://www.megacorp.com";
Value
Complete or relative URN as a string.
Default
None.
acronym, cite, code, dfn, em, kbd, samp, strong, var | NN 6 IE 4 DOM 1 |
All these objects reflect the corresponding HTML phrase elements of
the same name. Each of these phrase elements provides a context for
an inline sequence of content. Some of these elements are rendered in
ways to distinguish themselves from running text. See the HTML
element descriptions in Chapter 8 for
details. From a scripted standpoint, all phrase element objects share
the same set of properties, methods, and event handlers.
HTML Equivalent
<acronym>
<cite>
<code>
<dfn>
<em>
<kbd>
<samp>
<strong>
<var>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
None.
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
The address object reflects the
address element.
HTML Equivalent
<address>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
None.
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
A collection of elements nested within the current element. A
reference to document.all, for example, returns a
collection (array) of all element objects contained by the document,
including elements that may be deeply nested inside the
document's first level of elements. The collection
is sorted in source code order of the element tags. You can retrieve
a reference to an element with its ID by any of the following
syntaxes:
document.all.elementID
document.all["elementID"]
document.all("elementID"]
document.all.item("elementID")
document.all.namedItem("elementID")
The W3C DOM equivalent (the document.getElementById(
) method) operates only from the
document object, providing global reach to
elements throughout the entire document.
Object Model Reference
elementReference.all
Object-Specific Properties
Object-Specific Methods
item( )
|
namedItem( )
|
tags( )
|
urns( )
|
Object-Specific Event Handler Properties
None.
length | NN n/a IE 4 DOM n/a |
Returns the number of elements in the collection.
Example
var howMany = document.all.length;
Value
Integer.
item( ) | NN n/a IE 4 DOM n/a |
item(index[,
subindex]) Returns a single object or collection of objects corresponding to the
element matching the index value (or, optionally, the
index and subindex values).
Returned Value
One object or collection (array) of objects. If there are no matches
to the parameters, the returned value is null.
Parameters
- index
-
When the parameter is a zero-based integer, the returned value is a
single element corresponding to the specified item in source code
order (nested within the current element); when the parameter is a
string, the returned value is a collection of elements whose
id or name properties match
that string.
- subindex
-
If you specify a string value for the first parameter, you can use
the second parameter to specify a zero-based index that retrieves the
specified element from the collection whose id or
name properties match the first
parameter's string value.
namedItem( ) | NN n/a IE 6 DOM n/a |
namedItem(IDOrName) Returns a single object or collection of objects corresponding to the
element matching the parameter string value.
Returned Value
One object or collection (array) of objects. If there are no matches
to the parameters, the returned value is null.
Parameters
- IDOrName
-
The string that contains the same value and case as the desired
element's id or
name attribute.
tags( ) | NN n/a IE 4 DOM n/a |
tags(tagName) Returns a collection of objects (among all objects nested within the
current element) whose tags match the
tagName parameter.
Returned Value
A collection (array) of objects. If there are no matches to the
parameters, the returned value is an array of zero length.
Parameters
- tagName
-
A case-insensitive string that contains the element tag name only (no
angle brackets), as in document.all.tags("p").
urns( ) | NN n/a IE 5(Win) DOM n/a |
urns(URN) Returns a collection of nested element objects that have behaviors
attached to them and whose URNs match the
URN parameter.
Returned Value
A collection (array) of objects. If there are no matches to the
parameters, the returned value is an array of zero length.
Parameters
- URN
-
A string with a local or external behavior file URN.
A collection of all a elements with assigned
name attributes that make them behave as anchors
(instead of links). Collection members are sorted in source code
order. Navigator and Internet Explorer let you use array notation to
access a single anchor in the collection (e.g.,
document.anchors[0],
document.anchors["section3"]). Internet Explorer 4
also allows the index value to be placed inside parentheses instead
of brackets (e.g., document.anchors(0)). If you
want to use the anchor's name as an index value
(always as a string identifier), be sure to use the value of the
name attribute, rather than the
id attribute. To use the id
attribute in a reference to an anchor, access the object via a
document.all.elementID
(in IE only) or
document.getElementById("elementID")
reference.
Object Model Reference
document.anchors
Object-Specific Properties
Object-Specific Methods
item( )
|
namedItem( )
|
tags( )
|
urns( )
|
Object-Specific Event Handler Properties
None.
Returns the number of elements in the collection.
Example
var howMany = document.anchors.length;
Value
Integer.
item(index[, subindex])
item(index) Returns a single anchor object or collection of anchor objects
corresponding to the element matching the index value (or, optionally
in IE, the index and subindex
values).
Returned Value
One anchor object or collection (array) of anchor objects. If there
are no matches to the parameters, the returned value is
null.
Parameters
- index
-
When the parameter is a zero-based integer (required in Netscape 6),
the returned value is a single element that corresponds to the
specified item in source code order (nested within the current
element). When the parameter is a string, the returned value is a
collection of elements whose id or
name properties match that string.
- subindex
-
In IE only, if you specify a string value for the first parameter (IE
only), you can use the second parameter to specify a zero-based index
that retrieves the specified element from the collection with
id or name properties that
match the first parameter's string value.
namedItem( ) | NN 6 IE 6 DOM 1 |
namedItem(IDOrName) Returns a single anchor object or collection of anchor objects
corresponding to the element matching the parameter string value.
Returned Value
One anchor object or collection (array) of anchor objects. If there
are no matches to the parameters, the returned value is
null.
Parameters
- IDOrName
-
The string that contains the same value as the desired
element's id or
name attribute.
tags( ) | NN n/a IE 4 DOM n/a |
tags(tagName) Returns a collection of objects (among all objects nested within the
current collection) with tags that match the
tagName parameter. Implemented in all IE
collections (see the all.tags( ) method), but
redundant for collections of the same element type.
urns( ) | NN n/a IE 5(Win) DOM n/a |
urns(URN) See the all.urns( ) method.
The applet object reflects the
applet element.
HTML Equivalent
<applet>
Object Model Reference
[window.]document.appletName
[window.]document.getElementById("elementID")
Object-Specific Properties
align
|
alt
|
altHTML
|
archive
|
code
|
codeBase
|
dataFld
|
dataSrc
|
height
|
hspace
|
name
|
object
|
src
|
vspace
|
width
|
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
Defines the alignment of the element within its surrounding
container. Only partially implemented in Netscape 6.2. See Section 8.1.5
at the beginning of Chapter 8 for
the various meanings that different values bring to this property.
Example
document.getElementById("myApplet").align = "center";
Value
Any of the alignment constants: absbottom |
absmiddle | baseline |
bottom | left |
middle | right |
texttop | top.
Default
left
This is the text message to be displayed if the object or applet
fails to load. There is little indication that setting this property
on an existing applet object has any visual
effect.
Example
document.myApplet.alt= "Image Editor Applet";
Value
Any quoted string of characters, but HTML tags are not interpreted.
Default
None.
altHTML | NN n/a IE 4 DOM n/a |
Provides the HTML content to be displayed if the object or applet
fails to load. This can be a message, static image, or any other HTML
that best fits the scenario. There is little indication that setting
this property on an existing applet object has any
visual effect.
Example
document.myApplet.altHTML = "<img src='appletAlt.gif'>";
Value
Any quoted string of characters, including HTML tags.
Default
None.
Reflects the archive attribute of the
applet element. Only partially implemented in the
browsers. See the discussion of the archive
attribute in Chapter 8.
Example
if (document.applets["clock"].archive == "myClock.zip") {
// process for the found class file
}
Value
Case-sensitive URI as a string.
Default
None.
Provides the name of the Java applet class file set to the
code attribute. Not fully implemented in Netscape
7.
Example
if (document.applets["clock"].code == "XMAScounter.class") {
// process for the found class file
}
Value
Case-sensitive applet class filename as a string.
Default
None.
Provides the path to the directory holding the class file designated
in the code attribute. The
codebase attribute does not name the class file,
just the path. Not fully implemented in Netscape 7.
Example
if (document.applets["clock"].codeBase == "classes") {
// process for the found class file directory
}
Value
Case-sensitive pathname, usually relative to the directory storing
the current HTML document.
Default
None.
dataFld | NN n/a IE 4 DOM n/a |
It is unclear how you would use this property with an
applet object because the
dataFld and dataSrc properties
(as set in element attributes) are applied to individual
param elements.
Value
Case-sensitive identifier of the data source column.
Default
None.
dataSrc | NN n/a IE 4 DOM n/a |
It's unclear how you would use this property with an
applet object because the
dataFld and dataSrc properties
(as set in element attributes) are applied to individual
param elements.
Value
Case-sensitive identifier of the data source.
Default
None.
height, width | NN 6 IE 4 DOM 1 |
Indicate the height and width in pixels of the element as set by the
tag attributes. Changing the values does not necessarily change the
actual rectangle of the applet after it has loaded. Not fully
implemented in Netscape 7.
Example
var appletHeight = document.myApplet.height;
Value
Integer.
Default
None.
hspace, vspace | NN 6 IE 4 DOM 1 |
Indicate the pixel measure of horizontal and vertical margins
surrounding an applet. The hspace property affects
the left and right edges of the element equally; the
vspace affects the top and bottom edges of the
element equally. These margins are not the same as margins set by
style sheets, but they have the same visual effect.
Example
document.getElementById("myApplet").hspace = 5;
document.getElementById("myApplet").vspace = 8;
Value
Integer of pixel count.
Default
0
This is the identifier associated with the applet. Use the name when
referring to the object in the form
document.appletName.
Value
Case-sensitive identifier that follows the rules of identifier
naming: it may contain no whitespace, cannot begin with a numeral,
and should avoid punctuation except for the underscore character.
Default
None.
object | NN n/a IE 4 DOM n/a |
Returns a reference to the applet object so that a script can access
a property or method of the applet whose name is identical to a
property or method of the applet element object.
Value
Applet object (not the applet element object)
reference.
Default
None.
Internet Explorer defines this attribute as the URL for an associated
file. The src property is not a substitute for the
code and/or codebase
properties.
Value
Complete or relative URL as a string.
Default
None.
A collection of all the Java applets in the current element, sorted
in source code order. Navigator and Internet Explorer let you use
array notation to access a single applet in the collection (e.g.,
document.applets[0],
document.applets["clockApplet"]). Internet
Explorer allows the index value to be placed inside parentheses
instead of brackets (e.g., document.applets(0)).
If you wish to use the applet's name as an index
value (always as a string identifier), use the value of the
name attribute rather than the
id attribute. To use the id
attribute in a reference to an applet, access the object via a
document.all.elementID
(in IE only) or
document.getElementById("elementID")
reference.
Object Model Reference
document.applets[i]
Object-Specific Properties
Object-Specific Methods
Returns the number of elements in the collection.
Example
var howMany = document.applets.length;
Value
Integer.
item(index[, subindex])
item(index) Returns a single applet object or collection of applet objects
corresponding to the element matching the index value (or, optionally
in IE, the index and subindex
values).
Returned Value
One applet object or collection (array) of applet objects. If there
are no matches to the parameters, the returned value is
null.
Parameters
- index
-
When the parameter is a zero-based integer, the returned value is a
single element corresponding to the specified item in source code
order (nested within the current element); when the parameter is a
string, the returned value is a collection of elements whose
id or name properties match
that string.
- subindex
-
In IE only, if you specify a string value for the first parameter,
you can use the second parameter to specify a zero-based index that
retrieves the specified element from the collection whose
id or name properties match the
first parameter's string value.
namedItem( ) | NN 6 IE 6 DOM 1 |
namedItem(IDOrName) Returns a single applet object or collection of applet objects
corresponding to the element matching the parameter string value.
Returned Value
One applet object or collection (array) of applet objects. If there
are no matches to the parameters, the returned value is
null.
Parameters
- IDOrName
-
The string that contains the same value as the desired
element's id or
name attribute.
The area object reflects the
area element, which defines the shape,
coordinates, and destination of a clickable region of a client-side
image map. Navigator and Internet Explorer treat an
area object as a member of the
links collection, since an area
object behaves much like a link, but for a segment of an image.
HTML Equivalent
<area>
Object Model Reference
[window.]document.links[i]
[window.]document.getElementById("elementID")
Object-Specific Properties
alt
|
coords
|
hash
|
host
|
hostname
|
href
|
noHref
|
pathname
|
port
|
protocol
|
search
|
shape
|
target
|
|
|
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
Future nongraphical browsers may use the alt
property setting to display a brief description of the meaning of the
(invisible) image's hotspots.
Example
document.getElementById("elementID").alt = "To Next Page";
Value
Any quoted string of characters.
Default
None.
Defines the outline of the area to be associated with a particular
link or scripted action. Coordinate values are entered as a
comma-delimited list. If hotspots of two areas should overlap, the
area that is defined earlier in the code takes precedence.
Example
document.getElementById("mapArea2").coords = "25, 5, 50, 70";
Value
Each coordinate is a pixel length value, but the number of
coordinates and their order depend on the shape specified by the
shape attribute, which may optionally be
associated with the element. For shape="rect",
there are four coordinates (left, top, right, bottom); for
shape="circle", there are three coordinates
(center-x, center-y, radius); for shape="poly",
there are two coordinate values for each point that defines the shape
of the polygon.
Default
None.
This is that portion of the href
attribute's URL following the #
symbol, referring to an anchor location in a document. Do not include
the # symbol when setting the property.
Example
document.getElementById("mapArea2").hash = "section3";
Value
String.
Default
None.
Provides the combination of the hostname and port (if any) of the
server of the destination document for the area link. If the port is
explicitly part of the URL, the hostname and port are separated by a
colon, just as they are in the URL. If the port number is not
specified in an HTTP URL for IE, it automatically returns the
default, port 80.
Example
document.getElementById("mapArea2").host = "www.megacorp.com:80";
Value
String of hostname optionally followed by a colon and port number.
Default
Depends on server.
Provides the hostname of the server (i.e., a two-dot address
consisting of server name and domain) of the destination document for
the area link. The hostname property does not
include the port number.
Example
document.links[2].hostname = "www.megacorp.com";
Value
String of hostname (server and domain).
Default
Depends on server.
This is the URL specified by the element's
href attribute.
Example
document.links[2].href = "http://www.megacorp.com";
Value
String of complete or relative URL.
Default
None.
Specifies whether the area defined by the coordinates has a link
associated with it. When you set this property to
true, scriptable browsers no longer treat the
element as a link.
Example
document.links[4].noHref = "true";
Value
Boolean value: true | false.
Default
false
Provides the pathname component of the URL assigned to the
element's href attribute. This
consists of all URL information following the last character of the
domain name, including the initial forward slash symbol.
Example
document.getElementById("myLink").pathname = "/images/logoHiRes.gif";
Value
String.
Default
None.
Provides the port component of the URL assigned to the
element's href attribute. This
consists of all URL information following the colon after the last
character of the domain name. The colon is not part of the
port property value.
Example
document.getElementById("myLink").port = "80";
Value
String (a numeric value as string).
Default
None.
Indicates the protocol component of the URL assigned to the
element's href attribute. This
consists of all URL information up to and including the first colon
of a URL. Typical values are "http:",
"file:", "ftp:", and
"mailto:".
Example
document.getElementById("secureLink").protocol = "https:";
Value
String.
Default
None.
This is the URL-encoded portion of a URL assigned to the
href attribute that begins with the
? symbol. A document that is served up as the
result of the search also may have the search portion available as
part of the window.location property. You can
modify this property with a script. Doing so sends the URL and search
criteria to the server. You must know the format of data (usually
name/value pairs) expected by the server to perform this properly.
Example
document.getElementById("searchLink").search="?p=Tony+Blair&d=y&g=0&s=a&w=s&m=25";
Value
String starting with the ? symbol.
Default
None.
Indicates the shape of a server-side image map area with coordinates
that are specified with the coords attribute.
Example
document.getElementById("area51").shape = "circle";
Value
Case-insensitive shape constant as string: default
| rect |
rectangle |
circle |
poly | polygon.
Default
RECT (IE); empty string but
rect implied (Netscape 6).
This is the name of the window or frame that is to receive content as
the result of navigating to an area link. Such names are assigned to
frames by the frame element's
name attribute; for subwindows, the name is
assigned via the second parameter of the window.open(
) method. If you need the services of a
target attribute to open a linked page in a blank
browser window and you also need the HTML to validate under strict
HTML or XHTML DTDs, you can omit the target
attribute in the code, but assign a value to the
area element's
target property by script after the page loads.
Example
document.getElementById("homeArea").target = "_blank";
Value
String value of the window or frame name, or any of the following
constants (as a string): _parent |
_self | _top |
_blank. The _parent value
targets the frameset to which the current document belongs; the
_self value targets the current window; the
_top value targets the main browser window,
thereby eliminating all frames; and the _blank
value creates a new window of default size.
Default
None.
A collection of all area elements associated with
a map element. Notice that individual items of an
areas collection are also members of the
document-wide links collection
( document.links[] array). But the members of an
areas collection are local to a single
map element.
Object Model Reference
document.getElementById("mapElementID").areas
Object-Specific Properties
Object-Specific Methods
item( )
|
namedItem( )
|
tags( )
|
urns( )
|
Returns the number of elements in the collection.
Example
var howMany = document.areas.length;
Value
Integer.
item(index[, subindex])
item(index) Returns a single area object or collection of
area objects corresponding to the element matching
the index value (or, optionally in IE, the index
and subindex values).
Returned Value
One area object or collection (array) of
area objects. If there are no matches to the
parameters, the returned value is null.
Parameters
- index
-
When the parameter is a zero-based integer, the returned value is a
single element corresponding to the specified item in source code
order (nested within the current element); when the parameter is a
string, the returned value is a collection of elements whose
id or name properties match
that string.
- subindex
-
In IE only, if you specify a string value for the first parameter,
you can use the second parameter to specify a zero-based index that
retrieves the specified element from the collection whose
id or name properties match the
first parameter's string value.
namedItem( ) | NN 6 IE 6 DOM 1 |
namedItem(IDOrName) Returns a single area object or collection of
area objects corresponding to the element matching
the parameter string value.
Returned Value
One area object or collection (array) of
area objects. If there are no matches to the
parameters, the returned value is null.
Parameters
- IDOrName
-
The string that contains the same value as the desired
element's id or
name attribute.
tags( ) | NN n/a IE 4 DOM n/a |
tags(tagName) Returns a collection of objects (among all objects nested within the
current collection) with tags that match the
tagName parameter. Implemented in all IE
collections (see the all.tags( ) method), but
redundant for collections of the same element type.
urns( ) | NN n/a IE 5(Win) DOM n/a |
urns(URN) See the all.urns( ) method.
Attr, attribute | NN 6 IE 5 DOM 1 |
An abstract representation of an element's attribute
name/value pair is an object known in the W3C DOM vernacular as the
Attr object; in IE terminology, it is called an
attribute object. They are different names for the
same object. An attribute object is created in both environments via
the document.createAttribute( ) method; the
reference to the attribute object then becomes the parameter to an
element's setAttributeNode( )
method to insert that attribute object into the element. For example:
var newAttr = document.createAttribute("author");
newAttr.value = "William Shakespeare";
document.getElementById("hamlet").setAttributeNode(newAttr);
Some W3C DOM element methods (most notably, the
getAttributeNode( ) method) return attribute
objects, which have properties that may be accessed like any
scriptable object.
In the W3C DOM abstract model, the Attr object
inherits all properties and methods of the Node
object. Some Node object properties, however, are
not inherited by the attribute object in
IE/Windows until Version 6, even though they are implemented for
element and text nodes in Version 5.
HTML Equivalent
Any name/value pair inside a start tag.
Object Model Reference
[window.]document.getElementById("elementID").attributes[i]
[window.]document.getElementById("elementID").attributes.item(i)
[window.]document.getElementById("elementID").attributes.getNamedItem[attrName]
Object-Specific Properties
expando
|
name
|
ownerElement
|
specified
|
value
|
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
expando | NN n/a IE 6 DOM n/a |
Returns Boolean true if the attribute, once it is
inserted into an element, is not one of the native attributes for the
element. This property is false for an attribute
created by document.createAttribute( ) until the
attribute is added to the element (via the setAttributeNode(
) method), at which time the property's
value is reevaluated within the context of the
element's native attributes.
Example
var isCustomAttr =
document.getElementById("book3928").getAttributeNode("author").expando;
Value
Boolean value: true | false.
Default
false
This is the name portion of the name/value pair of the attribute. It
is identical to the nodeName property of the
Attr node. You may not modify the name of an
attribute by script because other dependencies may lead to document
tree confusion. Instead, replace the old attribute with a newly
created one, the name of which is a required parameter of the
document.createAttribute( ) method.
Example
if (myAttr.name == "author") {
// process author attribute
}
Value
String value.
Default
Empty string, although creating a new attribute requires a name.
ownerElement | NN 6 IE n/a DOM 2 |
Refers to the element that contains the current attribute object.
Until a newly created attribute is inserted into an element, this
property is null.
Example
if (myAttr.ownerElement.tagName == "fred") {
// process attribute of <fred> element
}
Value
Element node reference.
Default
null
Returns Boolean true if the value of the attribute
is explicitly assigned in the source code or adjusted by script. If
the browser reflects an attribute that is not explicitly set (IE does
this), the specified property for that value is
false, even though the attribute may have a
default value determined by the document's DTD. The
W3C DOM Level 2 indicates that the specified
property of a freshly created Attr object should
be true, but both IE 6 and Netscape 6.2 and later
leave it false until the attribute is inserted
into an element.
Example
if (myAttr.specified) {
// process attribute whose value is something other than DTD default
}
Value
Boolean value: true | false.
Default
false
Provides the value portion of the name/value pair of the attribute.
Identical to the nodeValue property of the
Attr node, as well as data accessed more directly
via an element's getAttribute( )
and setAttribute( ) methods. If you create a new
attribute object, you can assign its value via the
value property prior to inserting the attribute
into the element. Attribute node values are always strings, including
in IE, which otherwise allows Number or Boolean data types for the
corresponding properties.
Example
document.getElementById("hamlet").getAttributeNode("author").value = "Shakespeare";
Value
String value.
Default
Empty string, except in IE/Windows, which returns the string
undefined (that is, not a value whose type
evaluates to the undefined value).
attributes, NamedNodeMap | NN 6 IE 5 DOM 1 |
The object returned by the attributes property of
every W3C DOM element object is a collection (array) of references to
Attr (a.k.a. attribute)
objects. An attribute type of node always has a name associated with
it, which opens the way for methods of the collection of such nodes
to access them directly by name, rather than iterating through the
array in search of a matching node name. In the W3C DOM structure,
the abstract representation of this array of named nodes is called
the NamedNodeMap object, which shares some
properties and methods of the IE attributes
object. Since both objects refer to the same parts of a document
tree, they are treated here together. A couple of other W3C DOM
collections are also of the NamedNodeMap variety,
but your primary contact with the NamedNodeMap in
HTML documents is as a collection of Attr objects.
Collection members are sorted in source code order.
There are more direct ways to access an attribute of an element (such
as the getAttribute( ) or
getAttributeNode( ) methods of all elements). The
property and methods shown here, however, assume that your script has
been handed a collection of attributes independent of their host
element, and your processing starts from that point.
Object Model Reference
elementReference.attributes
Object-Specific Properties
Object-Specific Methods
getNamedItem( )
|
getNamedItemNS( )
|
item( )
|
removeNamedItem( )
|
removeNamedItemNS( )
|
setNamedItem( )
|
setNamedItemNS( )
|
|
Object-Specific Event Handler Properties
None.
Returns the number of elements in the collection.
Example
var howMany = document.getElementById("myTable").attributes.length;
Value
Integer.
getNamedItem( ) | NN 6 IE 6 DOM 1 |
getNamedItem("attributeName") Returns a single Attr object corresponding to the
attribute whose node name matches the parameter value.
Returned Value
Reference to one Attr object. If there is no match
to the parameter value, the returned value is
null.
Parameters
- attributeName
-
String corresponding to the name portion of an
attribute's name/value pair.
getNamedItemNS( ) | NN 6 IE n/a DOM 2 |
getNamedItemNS("namespaceURI",
"localName") Returns a single Attr object with a local name and
namespace URI that match the parameter values.
Returned Value
Reference to one Attr object. If there is no match
to the parameter values, the returned value is
null.
Parameters
- namespaceURI
-
URI string matching a URI assigned to a label earlier in the document.
- localName
-
The local name portion of the attribute.
item(index) Returns a single Attr object corresponding to the
element matching the index value.
Returned Value
Reference to one Attr object. If there is no match
to the index value, the returned value is null.
Unlike some other collections in IE, a string index value is not
allowed for the attributes object.
Parameters
- index
-
A zero-based integer corresponding to the specified item in source
code order.
removeNamedItem( ) | NN 6 IE 6 DOM 1 |
removeNamedItem("attributeName") Removes from the collection a single Attr object
corresponding to the attribute whose node name matches the parameter
value.
Returned Value
Reference to the removed Attr object. If there is
no match to the parameter value, the returned value is
null.
Parameters
- attributeName
-
String corresponding to the name portion of an
attribute's name/value pair.
removeNamedItemNS( ) | NN 6 IE n/a DOM 2 |
removeNamedItemNS("namespaceURI",
"localName") Removes from the collection a single Attr object
whose local name and namespace URI match the parameter values.
Returned Value
Reference to the removed Attr object. If there is
no match to the parameter values, the method generates an error.
Parameters
- namespaceURI
-
URI string matching a URI assigned to a label earlier in the document.
- localName
-
The local name portion of the attribute.
setNamedItem( ) | NN 6 IE 6 DOM 1 |
setNamedItem(attrObjectReference) Inserts a single Attr object into the current
collection of attributes. If the destination of the attribute is an
existing element, you may also use the setAttributeNode(
) method on the element to insert the
Attr object. When the setNamedItem(
) method is invoked, the browser first looks for a match
between the new attribute's name and existing
attribute names within the collection. If there is a match, the new
attribute replaces the original one; otherwise, the new attribute is
added to the collection.
Returned Value
Reference to an Attr object either created anew or
referenced from elsewhere in the document tree.
Parameters
- attrObjectReference
-
A reference to an Attr node object created through
document.createAttribute( ) or an
Attr node from another element in the document
tree.
setNamedItemNS( ) | NN 6 IE n/a DOM 2 |
setNamedItemNS(attrObjectReference) Inserts a single Attr object into the current
collection of attributes. If the destination of the attribute is an
existing element, you may also use the setAttributeNodeNS(
) method on the element to insert the
Attr object. When the setNamedItemNS(
) method is invoked, the browser first looks for a match
between the new attribute's pairing of local name
and namespace URI and existing attribute local names and namespace
URIs within the collection. If there is a match, the new attribute
replaces the original one; otherwise, the new attribute is added to
the collection.
Returned Value
Reference to an Attr object either created anew or
referenced from elsewhere in the document tree.
Parameters
- attrObjectReference
-
A reference to an Attr node object created through
document.createAttributeNS( ) or an
Attr node from another element in the document
tree.
b, big, i, s, small, strike, tt, u | NN 6 IE 4 DOM 1 |
All these objects reflect the HTML font style elements of the same
name. Each of these elements specifies a rendering style for an
inline sequence of content. All the elements are deprecated in HTML 4
in favor of style sheet attributes. See the HTML element descriptions
in Chapter 8 for details. From a scripted
standpoint, all font style element objects share the same set of
properties, methods, event handlers, and collections.
HTML Equivalent
<b>
<big>
<i>
<s>
<small>
<strike>
<tt>
<u>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
None.
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
A base object instructs the browser about the URL
path to the current document. This path is then used as the basis for
all relative URLs that are used to specify various
src and href attributes
throughout the document.
HTML Equivalent
<base>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
Provides the URL of a document whose server path is to be used as the
base URL for all relative references in the document. This is
typically the URL of the current document, but it can be set to
another path if it makes sense to your document organization and
directory structure.
Example
document.getElementById("myBase").href = "http://www.megacorp.com";
Value
String of complete or relative URL.
Default
Current document pathname.
Provides the name of the window or frame that is to receive content
as the result of navigating to a link or any other action on the page
that loads a new document. Such names are assigned to frames by the
frame element's
name attribute; for subwindows, the name is
assigned via the second parameter of the window.open(
) method. If you need the services of a
target attribute to open a linked page in a blank
browser window and you also need the HTML to validate under strict
HTML or XHTML DTDs, you can omit the target
attribute in the code, but assign a value to the
base element's
target property by script after the page loads.
Example
document.getElementById("myBase").target = "_blank";
Value
String value of the window or frame name, or any of the following
constants (as a string): _parent |
_self | _top |
_blank. The _parent value
targets the frameset to which the current document belongs; the
_self value targets the current window; the
_top value targets the main browser window,
thereby eliminating all frames; and the _blank
value creates a new window of default size.
Default
_self
A basefont element advises the browser of some
font information to be used as the basis for text rendering of the
current page below the basefont element. The
basefont element overrides the default font
settings in the browser's user preferences settings.
If you intend to alter this element by script, do so only via the
properties shown here or W3C DOM-compatible document tree
manipulations. Other approaches either risk the display of the
document or are not permitted by the browser.
HTML Equivalent
<basefont>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
Sets the font color of all text below the basefont
element.
Example
document.getElementsByTagName("basefont")[0].color = "#c0c0c0";
Value
Case-insensitive hexadecimal triplet or plain-language color name as
a string. See Appendix A for acceptable
plain-language color names.
Default
Browser default.
Indicates a hierarchy of font faces to use for the default font of a
section headed by a basefont element. The browser
looks for the first font face in the comma-delimited list of font
face names until it either finds a match in the client system or runs
out of choices, at which point the browser default font face is used.
Font face names must match the system font face names exactly.
Example
document.getElementById("myBaseFont").face = "Bookman, Times Roman, serif";
Value
One or more font face names in a comma-delimited list within a
string. You may use real font names or the recognized generic faces:
serif | sans-serif |
cursive | fantasy |
monospace.
Default
Browser default.
Provides the size of the font in the 1-7 browser relative scale.
Example
document.getElementById("myBaseFont").size = "+1";
Value
Either an integer (as a quoted string) or a quoted relative value
consisting of a + or - symbol
and an integer value.
Default
3
The bdo element is designed to assist in instances
when, due to various conversions during text processing, the normal
bidirectional algorithms must be explicitly overridden. The primary
property of this object is dir, which is shared
among all other element objects.
HTML Equivalent
<bdo>
Object-Specific Properties
None.
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
bgsound | NN n/a IE 4 DOM n/a |
A bgsound element defines a sound file that is to
play in the background while the user visits the page. Set properties
to control the volume and how many times the sound track plays even
after the sound file has loaded. A few properties, such as
innerHTML and innerText, are
exposed in the Windows version, but they don't apply
to an element that does not have an end tag.
HTML Equivalent
<bgsound>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
balance | NN n/a IE 4 DOM n/a |
Specifies how the audio is divided between the left and right
speakers. Once this attribute value is set in the element, its value
cannot be changed by script control.
Example
var currBal = document.getElementsByTagName("bgsound")[0].balance;
Value
A signed integer between -10,000 and +10,000. A value of
0 is equally balanced on both sides. A negative
value means the left side is dominant; a positive value means the
right side is dominant.
Default
0
Specifies the number of times the sound plays. Assigning a value of
-1 means the sound plays continuously until the page is unloaded.
Example
document.getElementById("mySound").loop = 3;
Value
Integer.
Default
1
Provides the URL of the sound file to be played. Change tunes by
assigning a new URL to the property. The new tune plays according to
the loop property setting.
Example
document.getElementById("tunes").src = "sounds/blues.aif";
Value
Complete or relative URL as a string.
Default
None.
volume | NN n/a IE 4 DOM n/a |
Specifies how loud the background sound plays relative to the maximum
sound output level as adjusted by user preferences in the client
computer. Maximum volume—a setting of zero—is only as
loud as the user has set the Sound
control panel. Attribute adjustments are negative values as low as
-10,000 (although most users lose the sound at values much higher
than that value).
Example
var currVolume = document.getElementById("themeSong").volume;
Value
Integer.
Default
Varies with operating system and sound settings.
blockquote | NN 6 IE 4 DOM 1 |
The blockquote object reflects the
blockquote element, which is intended to set off a
long, block-level quote inside a document.
HTML Equivalent
<blockquote>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
Provides a URL pointing to an online source document from which the
quotation is taken. This is not in any way a mechanism for copying or
extracting content from another document. IE 6 for Windows
incorrectly calls this property clear. No
mainstream browser does anything special with this information.
Value
Any valid URL to a document on the World Wide Web, including absolute
or relative URLs.
Default
None.
The body object reflects the
body element, which is distinct from the
document object. The body
object refers to just the element and its nested content. There can
be only one body element in an HTML page, so both the IE and W3C DOMs
provide a shortcut reference to the object,
document.body. Event handlers listed here appear
as attributes in the <body> tag, but in
truth are document-level events (best referenced in property form as
document.eventName).
While IE for the Mac doesn't share the sets of
client and scroll properties with all element objects, those
properties are defined for the body object.
In its effort to institute the standards-compatible mode in IE 6 for
Windows (see the DOCTYPE element in Chapter 8), Microsoft has rendered useless the old
trick of using the body element's
clientHeight and clientWidth
properties to obtain the equivalent of Netscape's
window.innerHeight and
window.innerWidth properties. In
standards-compatibility mode (where
document.compatMode ==
"CSS1Compat"), you must use the
html element's
clientHeight and clientWidth
properties to find these values. Use these effective reference
shortcuts:
document.body.parentNode.clientHeight
document.body.parentNode.clientWidth
HTML Equivalent
<body>
Object Model Reference
[window.]document.body
Object-Specific Properties
alink
|
background
|
bgColor
|
bgProperties
|
bottomMargin
|
leftMargin
|
link
|
noWrap
|
rightMargin
|
scroll
|
text
|
topMargin
|
vLink
|
|
|
Object-Specific Methods
Object-Specific Event Handler Properties
Handler
|
IE Windows
|
IE Mac
|
NN
|
W3C DOM
|
onafterprint
|
5
|
n/a
|
n/a
|
n/a
|
onbeforeprint
|
5
|
n/a
|
n/a
|
n/a
|
onbeforeunload
|
4
|
n/a
|
n/a
|
n/a
|
onload
|
3
|
3.01
|
2
|
2
|
onselect
|
n/a
|
n/a
|
6
|
n/a
|
onunload
|
3
|
3.01
|
2
|
2
|
Indicates a color of a hypertext link as it is being clicked. The
color is applied to the link text or border around an image or object
embedded within an a element. See also
link and vLink properties for
unvisited and visited link colors. The deprecated but
backward-compatible version of this property is the
alinkColor property of the
document object.
Example
document.body.aLink = "green";
Value
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names.
Default
#0000FF
background | NN 6 IE 4 DOM 1 |
Provides the URL of the background image for the entire document. If
you set a bgColor to the element as well, the
color appears if the image fails to load; otherwise, the image
overlays the color.
Example
document.body.background = "images/watermark.jpg";
Value
Complete or relative URL to the background image file.
Default
None.
Provides the background color of the element. Even if the
bgcolor attribute or bgColor
property is set with a plain-language color name, the returned value
is always a hexadecimal triplet.
Example
document.body.bgColor = "yellow";
Value
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names.
Default
Varies with browser and operating system.
bgProperties | NN n/a IE 4 DOM n/a |
Specifies whether the background image remains in a fixed position or
scrolls as a user scrolls the page. When the background image is set
to remain in a fixed position, scrolled content flows past the
background image very much like film credits roll past a background
image on the screen.
Example
document.body.bgProperties = "fixed";
Value
An empty string (indicating the normal scrolling behavior) or the
case-insensitive constant string fixed.
Default
Empty string.
bottomMargin | NN n/a IE 4 DOM n/a |
Indicates the amount of blank space between the very end of content
and the bottom of a scrollable page. The setting has no visual effect
if the length of the content or size of the window does not cause the
window to scroll. The default value is for the end of content to be
flush with the end of the document, but in the Macintosh version of
Internet Explorer, there is about a 10-pixel margin visible even when
the property is set to zero. Larger sizes are reflected properly.
This property offers somewhat of a shortcut or alternative to setting
the marginBottom style sheet property for the
body element object.
Example
document.body.bottomMargin = 20;
Value
An integer value (zero or greater) of the number of pixels of clear
space at the bottom of the document.
Default
0
leftMargin | NN n/a IE 4 DOM n/a |
Provides the width in pixels of the left margin of the
body element in the browser window or frame. By
default, the browser inserts a small margin to keep content from
abutting the left edge of the window. Setting the property to an
empty string is the same as setting it to zero.
Example
document.body.leftMargin = 16;
Value
Integer of pixel count.
Default
10 (Windows); 8 (Macintosh).
Indicates the color of a hypertext link that has not been visited
(that is, the URL of the link is not in the
browser's cache). This is one of three states for a
link: unvisited, active, and visited. The color is applied to the
link text or border around an image or object embedded within an
a element. This property has the same effect as
setting the document object's
linkColor property.
Example
document.body.link = "#00FF00";
Value
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names.
Default
#0000FF
Specifies whether the browser should render the body content as wide
as necessary to display a line of nonbreaking text on one line. Abuse
of this attribute can force the user into a great deal of
inconvenient horizontal scrolling of the page to view all of the
content.
Example
document.body.noWrap = "true";
Value
Boolean value: true | false.
Default
false
rightMargin | NN n/a IE 4 DOM n/a |
Provides the width in pixels of the right margin of the
body element in the browser window or frame. By
default, the browser inserts a small margin to keep content from
abutting the right edge of the window (except on the Macintosh).
Setting the property to an empty string is the same as setting it to
zero.
Example
document.body.leftMargin = 16;
Value
Integer of pixel count.
Default
10 (Windows); 0 (Macintosh).
scroll | NN n/a IE 4 DOM n/a |
Specifies whether the window (or frame) displays scrollbars when the
content exceeds the window size. If your document specifies a
standards-compatible DOCTYPE definition (see Chapter 8), the scroll property
does not respond to changes for the body element.
Nor does the html element object gain this
property, as Microsoft's developer documentation
purports.
Example
document.body.scroll = "no";
Value
Not exactly a Boolean value. Requires one of the following string
values: yes | no |
auto.
Default
yes
Indicates the color of text for the entire document body. Equivalent
to the foreground color.
Example
document.body.text = "darkred";
Value
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names.
Default
Browser default (user customizable).
topMargin | NN n/a IE 4 DOM n/a |
Provides the width in pixels of the top margin of the
body element in the browser window or frame. By
default, the browser inserts a small margin to keep content from
abutting the top edge of the window. Setting the property to an empty
string is the same as setting it to zero.
Example
document.body.topMargin = 16;
Value
Integer of pixel count.
Default
15 (Windows); 8 (Macintosh).
Indicates the color of a hypertext link that has been visited
recently. The color is applied to the link text or border around an
image or object embedded within an a element. See
also link and aLink properties
for unvisited and clicked link colors. The deprecated but
backward-compatible version of this property is the
vlinkColor property of the
document object.
Example
document.body.vLink = "gold";
Value
A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names.
Default
#551a8b (Navigator 4); #800080
(Internet Explorer 4 Windows); #006010 (Internet
Explorer 4 Macintosh).
createTextRange( ) | NN n/a IE 4(Win) DOM n/a |
Creates a TextRange object from the rendered text
content of the current element. See the TextRange
object for details.
Returned Value
TextRange object.
Parameters
None.
The br object reflects the br
element.
HTML Equivalent
<br>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
Object-Specific Methods
None.
Element-Specific Event Handler Attributes
None.
Tells the browser how to treat the next line of text following a
br element if the current text is wrapping around
a floating image or other object. The value you use depends on the
side of the page to which one or more inline images are pegged and
how you want the next line of text to be placed in relation to those
images.
Example
document.getElementById("specialBreak").clear = "all";
Value
Case-insensitive string of any of the following constants:
all | left |
none | right.
Default
none
The button object reflects the
button element. While IE for the Mac
doesn't share the sets of client- and scroll-
properties with all element objects, those properties are defined for
the button object. See the discussion of the
button element in Chapter 8 to see how it differs from the
input element of type button.
HTML Equivalent
<button>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
dataFld
|
dataFormatAs
|
dataSrc
|
form
|
name
|
status
|
type
|
value
|
|
|
Object-Specific Methods
Object-Specific Event Handler Properties
None.
dataFld | NN n/a IE 4 DOM n/a |
Used with IE data binding to associate a remote data source column
name to a button object's label.
A datasrc attribute must also be set for the
element. Setting both the dataFld and
dataSrc properties to empty strings breaks the
binding between element and data source.
Example
document.getElementById("myButton").dataFld = "linkURL";
Value
Case-sensitive identifier of the data source column.
Default
None.
dataFormatAs | NN n/a IE 4 DOM n/a |
Used with IE data binding, this property advises the browser whether
the source material arriving from the data source is to be treated as
plain text or as tagged HTML.
Example
document.getElementById("myButton").dataFormatAs = "html";
Value
String constant values: text |
html.
Default
text
dataSrc | NN n/a IE 4 DOM n/a |
Used with IE data binding to specify the ID of the
page's object element that loads
the data source object for remote data access. Content from the data
source is specified via the datafld attribute in
the button element. Setting both the
dataFld and dataSrc properties
to empty strings breaks the binding between element and data source.
Example
document.getElementById("myButton").dataSrc = "DBSRC3";
Value
Case-sensitive identifier of the object element.
Default
None.
Returns a reference to the form element that
contains the current element (if any).
Example
var theForm = event.srcElement.form;
Value
Object reference.
Default
None.
This is the identifier associated with the element when used as a
form control. The value of this property is submitted as one-half of
the name/value pair when the form is submitted to the server. Names
are hidden from user view, since control labels are assigned via
other means, depending on the control type. Form control names may
also be used by script references to the objects.
Example
document.forms[0].compName.name = "company";
Value
Case-sensitive identifier that follows the rules of identifier
naming: it may contain no whitespace, cannot begin with a numeral,
and should avoid punctuation except for the underscore character.
Default
None.
status | NN n/a IE 4 DOM n/a |
Unlike the status property of other types of form
controls, the property has no visual or functional impact on the
button.
Value
Boolean value: true | false; or
null.
Default
null
Specifies whether the button element is specified
as a button, reset, or
submit style button.
Example
if (evt.target.type == "button") {
// process button element
}
Value
One of the three constants (as a string): button |
reset | submit.
Default
button
Provides the current value associated with the form control that is
submitted with the name/value pair for the element. Unlike the
button-type input element object, this
value property's value is unseen
by the user; the label is set by the element's
content ( innerHTML property or nested node).
Example
var val = document.getElementById("myButton").value;
Value
String.
Default
None.
createTextRange( ) | NN n/a IE 4(Win) DOM n/a |
Creates a TextRange object containing the
button's label text. See the
TextRange object.
Returned Value
TextRange object.
Parameters
None.
The caption object reflects the
caption element, which must always be nested
inside a table element. IE/Mac implements the
client and scroll property sets for this object.
HTML Equivalent
<caption>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
Determines the position of the caption in the table. See the
align attribute of the caption
element in Chapter 8 for details on the
interaction between the align and
vAlign attributes and properties in IE for
Windows. The W3C DOM uses the align property
predominantly for placing the caption above or below the table.
Example
document.getElementById("myCaption").align = "bottom";
Value
Any of the following constants (as a string):
bottom | left |
right | top.
Default
top
vAlign | NN n/a IE 4 DOM n/a |
Specifies whether the table caption appears above or below the table.
Example
document.getElementById("tabCaption").vAlign = "bottom"
Value
Case-insensitive constant (as a string): bottom |
top.
Default
top
A collection of all td elements contained within a
single tr element. Collection members are sorted
in source code order.
Object Model Reference
document.getElementById("rowID").cells
Object-Specific Properties
Object-Specific Methods
item( )
|
namedItem( )
|
tags( )
|
urns( )
|
Object-Specific Event Handler Properties
None.
Returns the number of elements in the collection.
Example
var howMany = document.getElementById("myTable").rows[0].cells.length;
Value
Integer.
item(index[, subindex])
item(index) Returns a single td object or collection of
td objects corresponding to the element matching
the index value (or, optionally in IE, the index
and subindex values).
Returned Value
One td object or collection (array) of
td objects. If there are no matches to the
parameters, the returned value is null.
Parameters
- index
-
When the parameter is a zero-based integer, the returned value is a
single element corresponding to the specified item in source code
order (nested within the current element); when the parameter is a
string (IE only), the returned value is a collection of elements
whose id properties match that string.
- subindex
-
In IE only, if you specify a string value for the first parameter,
you can use the second parameter to specify a zero-based index that
retrieves the specified element from the collection whose
id properties match the first
parameter's string value.
namedItem( ) | NN 6 IE 6 DOM 1 |
namedItem("ID") Returns a single td object or collection of
td objects corresponding to the element matching
the parameter string value.
Returned Value
One td object or collection (array) of
td objects. If there are no matches to the
parameters, the returned value is null.
Parameters
- ID
-
The string that contains the same value as the desired
element's id attribute.
tags( ) | NN n/a IE 4 DOM n/a |
tags("tagName") Returns a collection of objects (among all objects nested within the
current collection) whose tags match the
tagName parameter. Implemented in all IE
collections (see the all.tags( ) method), but
redundant for collections of the same element type.
urns( ) | NN n/a IE 5(Win) DOM n/a |
urns(URN) See the all.urns( ) method.
The center object reflects the
center element. The W3C DOM does not support the
deprecated HTML 4 center element. For backward
compatibility, Netscape 6 treats the element as earlier browsers do,
but the scriptable element is treated as a span
object, whose default text-align style is set to
center.
HTML Equivalent
<center>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
None.
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
See input (type="checkbox").
childNodes, NodeList | NN 6 IE 5 DOM 1 |
The object returned by the childNodes property of
several W3C DOM objects is a collection (array) of references to
Node objects that are immediate children of the
current node object. In the W3C DOM structure, the abstract
representation of this array is called the
NodeList object, which shares some properties and
methods of the IE childNodes object. Since both
objects refer to the same parts of a document tree, they are treated
here together. Collection members are sorted in source code order.
Object Model Reference
nodeReference.childNodes
Object-Specific Properties
Object-Specific Methods
Object-Specific Event Handler Properties
None.
Returns the number of nodes in the collection.
Example
var howMany = document.getElementById("myTable").attributes.length;
Value
Integer.
item(index) Returns a single Node object corresponding to the
element matching the index value.
Returned Value
Reference to one Node object. If there is no match
to the index value, the returned value is null.
Unlike some other collections in IE, a string index value is not
allowed for the childNodes object.
Parameters
- index
-
A zero-based integer corresponding to the specified item in source
code order (nested within the current node).
urns( ) | NN n/a IE 5(Win) DOM n/a |
urns(URN) See the all.urns( ) method.
children | NN n/a IE 4 DOM n/a |
A collection of all elements contained in the current element. Note
that unlike the childNodes collection,
children counts only elements and not text nodes.
Collection members are sorted in source code order. Internet Explorer
lets you use array notation or parentheses to access a single element
in the collection.
Object Model Reference
document.getElementById("elementID").children(i)
document.getElementById("elementID").children[i]
Object-Specific Properties
Object-Specific Methods
item( )
|
namedItem( )
|
tags( )
|
urns( )
|
Object-Specific Event Handler Properties
None.
length | NN n/a IE 4 DOM n/a |
Returns the number of elements in the collection.
Example
var howMany = document.body.children.length;
Value
Integer.
item( ) | NN n/a IE 4 DOM n/a |
item(index) Returns an element object corresponding to the element matching the
index value in source code order.
Returned Value
Reference to an element object. If there is no matches to the
parameter, the returned value is null.
Parameters
- index
-
A zero-based integer corresponding to the specified item in source
code order (nested within the current element).
namedItem( ) | NN n/a IE 6 DOM n/a |
namedItem(IDOrName) Returns an element object or collection of objects corresponding to
the element matching the parameter string value.
Returned Value
One element object or collection (array) of element objects. If there
are no matches to the parameters, the returned value is
null.
Parameters
- IDOrName
-
The string that contains the same value as the desired
element's id or
name attribute.
tags( ) | NN n/a IE 4 DOM n/a |
tags(tagName) Returns a collection of objects (among all objects nested within the
current collection) whose tags match the
tagName parameter. Implemented in all IE
collections (see the all.tags( ) method), but
redundant for collections of the same element type.
urns( ) | NN n/a IE 5(Win) DOM n/a |
urns(URN) See the all.urns( ) method.
clipboardData | NN n/a IE 5(Win) DOM n/a |
The clipboardData object (accessible as a property
of a window or frame object) is
a temporary container that scripts in IE 5 and later for Windows can
use to transfer text data, particularly during script-controlled
operations that simulate cutting, copying, and pasting, or that
control dragging. Your script controls what data is stored in the
clipboardData object, such as just the text of an
element, an element's entire HTML, or the URL of an
image. For example, a page for children could display simple icon
images of several different kinds of animals. If the user starts
dragging the dog icon, the script initiated by the
img element's
onDragStart event handler stores a custom
attribute value of that element (perhaps the URL of a pretty dog
photo) into the clipboardData object. When the
user drops the icon into the designated area, the
onDrop event handler's function
reads the clipboardData object's
data and loads the photo image into position on the page.
Data stored in this object survives navigation to other pages within
the same domain and protocol. Therefore, you can use it to pass text
data (including arrays that have been converted to strings by the
Array.join( ) method) from one page to another
without using cookies or location.search strings.
But this is not the system clipboard (for security reasons).
For more information on transferring data via this object and the
event.dataTransfer object, visit http://msdn.microsoft.com/workshop/author/datatransfer/overview.asp.
HTML Equivalent
None.
Object Model Reference
[window.]clipboardData
Object-Specific Properties
Object-Specific Methods
clearData( )
|
getData( )
|
setData( )
|
Object-Specific Event Handler Properties
None.
dropEffect, effectAllowed | NN n/a IE 5(Win) DOM n/a |
These two properties belong to the clipboardData
object by inheritance from the dataTransfer
object, to which they genuinely apply. Ignore these properties for
the clipboardData object.
clearData( ) | NN n/a IE 5(Win) DOM n/a |
clearData([dataFormat]) Removes data from the clipboardData object.
Returned Value
None.
Parameters
- dataFormat
-
An optional string specifying a single format for the data to be
removed. Earlier plans to allow multiple data types appear to have
fallen through. As of IE 6, the only reliable format is
Text. Omitting the parameter removes all data of
all types.
getData( ) | NN n/a IE 5(Win) DOM n/a |
getData(dataFormat) Returns a copy of data from the clipboardData
object. The clipboardData contents remain intact
for subsequent reading in other script statements.
Returned Value
String.
Parameters
- dataFormat
-
A string specifying the format for the data to be read. Earlier plans
to allow multiple data types appear to have fallen through. As of IE
6, the only reliable format is Text.
setData( ) | NN n/a IE 5(Win) DOM n/a |
setData(dataFormat,
stringData) Stores string data in the clipboardData object.
Returns Boolean true if the assignment is
successful
Returned Value
Boolean value: true | false.
Parameters
- dataFormat
-
A string specifying the format for the data to be read. Earlier plans
to allow multiple data types appear to have fallen through. As of IE
6, the only reliable format is Text. While the
method accepts URL as a format, reading a set
value in that format is not successful.
- stringData
-
Any string value, including strings that contain HTML tags.
col, colgroup | NN 6 IE 4 DOM 1 |
The col object reflects the col
element; the colgroup object reflects the
colgroup element. Both elements provide ways of
assigning multiple adjacent columns to groups for convenience in
assigning styles, widths, and other visual treatments.
HTML Equivalent
<col>
<colgroup>
Object Model Reference
[window.]document.getElementById("elementID")
Object-Specific Properties
align
|
ch
|
chOff
|
span
|
vAlign
|
width
|
|
|
|
|
Object-Specific Methods
None.
Object-Specific Event Handler Properties
None.
Defines the horizontal alignment of content within cells covered by
the col or colgroup element.
Example
document.getElementById("myCol").align = "center";
Value
Any of the three horizontal alignment constants:
center | char |
left | right.
Default
left
Defines the text character used as an alignment point for text within
a column or column group (reflecting the char
attribute). This property is normally of value only for the
align attribute set to "char".
In practice, neither IE nor Navigator respond to these properties.
Example
document.getElementById("myCol").ch = ".";
Value
Single character string.
Default
None.
Defines the offset point at which the character specified by the
char attribute is to appear within a cell. In
practice, neither IE 6 nor Netscape 6 respond to these properties.
Example
document.getElementById("myCol").chOff = "80%";
Value
String value of the number of pixels or percentage (within the cell).
Default
None.
Provides the number of adjacent columns for which the
element's attribute and style settings apply.
Example
document.getElementById("myColgroup").span = 2;
Value
Integer.
Default
1
Provides the manner of vertical alignment of text within the column
grouping's cells.
Example
document.getElementById("myCol").vAlign = "baseline";
Value
Case-insensitive constant (as a string): baseline
| bottom | middle |
top.
Default
middle
Provides the width in pixels of each column of the column grouping.
Changes to these values are immediately reflected in reflowed content
on the page.
Example
document.getElementById("myColgroup").width = 150;
Value
Integer.
Default
None.
comment, Comment | NN 6 IE 4 DOM 1 |
The comment object reflects the
! element in an HTML document. But in a W3C DOM
environment, such as Netscape 6, this object is not a genuine element
in the context of the W3C DOM abstract model. Instead, the object is
simply a special kind of node. Such a node has a
nodeType value of 8, which identifies it as a
Comment node. A Comment node
has the following inheritance chain in the DOM abstract model:
Node-> CharacterData-> Comment.
While a Comment node has special values
automatically assigned to some of its properties (such as
nodeValue), a Comment node has
no properties or methods beyond the ones inherited from the
Node and CharacterData objects.
Node properties and methods are discussed earlier
in this chapter among the shared items;
CharacterData properties and methods are covered
in detail with the Text object, which also
inherits from CharacterData, and is more likely to
be scripted.
To reference a comment element, use relative element or node
properties. While IE provides an id property by
virtue of its inheritance model, you cannot assign an identifier to
the element via an id attribute. Such an element
in IE does, however, have a tag name value of !.
Therefore, you can reference an IE HTML comment element via the
collection of elements returned by the
document.all.tags("!") method.
HTML Equivalent
<!--comment text-->
Object Model Reference
nodeReference
Object-Specific Properties
Object-Specific Methods
appendData( )
|
deleteData( )
|
insertData( )
|
replaceData( )
|
substringData( )
|
|
|
|
Object-Specific Event Handler Properties
None.
Provides the text content of the comment. See
Text.data.
Provides the character count of the comment data. See
Text.length.
Provides the text content of the element. Due to the nature of this
element, the value of the text property is identical to the values of
the innerHTML and outerHTML
properties. Changes to this property do not affect the text of the
comment as viewed in the browser's source code
version of the document. This property is not available in IE
4/Macintosh.
Example
document.all.tags("!")[4].text = "Replaced comment, but no one will know.";
Value
String.
Default
None.
appendData(), deleteData(), insertData(), replaceData( ), substringData( ) | NN 6 IE 6 DOM 1 |
Provide methods for manipulating comment text. See these methods in
the Text object.
CSSImportRule, CSSMediaRule, CSSPageRule | |
See CSSRule.
cssRule, CSSRule, rule | NN 6 IE 5 DOM 2 |
A style sheet rule object is a member of the collection of
styleSheet objects in the document. The IE and W3C
DOMs have different syntax for referencing each of these rule
objects. For IE, the reference is via the rules
collection (a single object being known as a rule
object); for W3C, as implemented in Netscape 6 and IE 5 for the
Macintosh, the reference is via the cssRules
collection (a single object being known as a
cssRule object). Note that the
cssRule object is not in the Windows version of IE
through Version 6.
The corresponding W3C DOM abstract object is called the
CSSRule object, but that form of the object name
is important only to scripters who wish to modify the prototype
properties and methods of the CSSRule object in
Netscape 6. The W3C DOM goes further to define special types of
CSSRule objects for each of the
@ rule types (CSSImportRule,
CSSMediaRule, and so on). A member of the
cssRules collection can be any one of those types,
and is identified as such by its type property.
Each type has its own set of properties and/or methods that apply to
that cssRule type. In the item property and method
listings below, observe the type(s) for which they apply. By and
large, however, the inline rules you will script are of the
CSSStyleRule type.
Use scriptable access to a rule or
cssRule object with caution. If you modify a
rule's selector or style definition, the changes
affect the entire document, and could, with a misplaced colon, ruin
other rules in the document. To toggle among two or more styles for a
single element, class, or element type, it is generally more reliable
and efficient to use other techniques that work with multiple rules
(swapping className assignments on elements) or
multiple style sheets (enabling and disabling
styleSheet objects). But for the sake of the
completeness of the object model, the W3C DOM in particular provides
full access to style sheet rule pieces if you absolutely need them.
Object Model Reference
document.styleSheets[i].rules[j]
document.styleSheets[i].cssRules[j]
Object-Specific Properties
cssRules
|
cssText
|
encoding
|
href
|
media
|
parentRule
|
parentStyleSheet
|
readOnly
|
selectorText
|
style
|
styleSheet
|
type
|
Object-Specific Methods
deleteRule( )
|
insertRule( )
|
Object-Specific Event Handler Properties
None.
cssRules | NN 6 IE n/a DOM 2 |
Returns a collection of cssRule objects nested
within an @media rule.
W3C DOM CSSRule Types
CSSMediaRule
Value
Reference to a cssRules collection object.
Default
Array of zero length.
cssText | NN 6 IE 5(Mac) DOM 2 |
Indicates the complete text of the style sheet rule, including
selector and attribute name/value pairs inside curly braces. IE 6 for
Windows provides no equivalent property. In supporting browsers,
changes do not influence the object or rendering.
W3C DOM CSSRule Types
All.
Example
document.styleSheets[0].cssRules[2].cssText = "td {text-align:center}";
Value
String.
Default
None.
encoding | NN 6 IE n/a DOM 2 |
Returns the character set code (e.g., ISO-8859-1
or UTF-8) associated with an
@charset rule.
W3C DOM CSSRule Types
CSSCharsetRule
Value
String.
Default
None.
Returns the URI of the external style sheet file imported via an
@import rule.
W3C DOM CSSRule Types
CSSImportRule
Value
String.
Default
None.
Returns the media type specified for an @import or
@media rule.
W3C DOM CSSRule Types
CSSImportRule
CSSMediaRule
Value
String constant for media types supported by the browser (e.g.,
screen or print).
Default
all
|