Dynamic HTML: The Definitive Reference, 2rd Ed.Dynamic HTML: The Definitive ReferenceSearch this book

9.5. Shared Object Properties, Methods, and Events

Both the proprietary Internet Explorer DOM and W3C DOM expose a wide range of properties (including event handler properties) and methods almost universally across objects that reflect HTML elements. Rather than repeat the descriptions of these items ad nauseam in the reference listing, I am listing their details only once. Due to the large number of shared items (80 properties, 60 methods, and 72 event types), these shared items do not appear in the lists of properties, methods, and events for each object in the rest of this chapter, but they are available for practically every HTML element object (within the browser or standard version range indicated in each listing).

Obviously, the shared properties or methods that are meaningless except for rendered element objects may not be available to nonrendered elements. For example, invoking the IE scrollIntoView( ) method of a style element object is meaningless because the style element presents no content of its own on the page to which a window could scroll. Such items are typically part of the DOMs simply because the browsers' internal architectures utilize an inheritance mechanism that empowers all element objects with the same basic items, even if they have no particular application. You should get to know the shared items well, and refer to the object-specific items later in this chapter when you need their special powers.

In the following item descriptions, the example code uses the term elementID to refer to the identifier assigned to the id attribute of the element. In your scripts, substitute the object's true ID for the placeholder used here. Here is a list of the common items:

9.5.1. Properties

ATTRIBUTE_NODE

CDATA_SECTION_NODE

COMMENT_NODE

DOCUMENT_FRAGMENT_NODE

DOCUMENT_NODE

DOCUMENT_TYPE_NODE

ELEMENT_NODE

ENTITY_NODE

ENTITY_REFERENCE_NODE

NOTATION_NODE

PROCESSING_INSTRUCTION_NODE

TEXT_NODE

accessKey

all[]

attributes[]

baseURI

behaviorUrns[]

canHaveChildren

canHaveHTML

childNodes[]

children

cite

className

clientHeight

clientLeft

clientTop

clientWidth

contentEditable

currentStyle

dateTime

dir

disabled

document

filters[]

firstChild

hideFocus

id

innerHTML

innerText

isContentEditable

isDisabled

isMultiLine

isTextEdit

lang

language

lastChild

localName

namespaceURI

nextSibling

nodeName

nodeType

nodeValue

offsetHeight

offsetLeft

offsetParent

offsetTop

offsetWidth

outerHTML

outerText

ownerDocument

parentElement

parentNode

parentTextEdit

prefix

previousSibling

readyState

recordNumber

runtimeStyle

scopeName

scrollHeight

scrollLeft

scrollTop

scrollWidth

sourceIndex

style

tabIndex

tagName

tagUrn

title

uniqueID

 

9.5.2. Methods

addBehavior( )

addEventListener( )

appendChild( )

applyElement( )

attachEvent( )

blur( )

clearAttributes( )

click( )

cloneNode( )

componentFromPoint( )

contains( )

createControlRange( )

detachEvent( )

dispatchEvent( )

doScroll( )

dragDrop( )

fireEvent( )

focus( )

getAdjacentText( )

getAttribute( )

getAttributeNode( )

getAttributeNodeNS( )

getAttributeNS( )

getBoundingClientRect( )

getClientRects( )

getElementsByTagName( )

getElementsByTagNameNS( )

getExpression( )

hasAttribute( )

hasAttributeNS( )

hasAttributes( )

hasChildNodes( )

insertAdjacentElement( )

insertAdjacentHTML( )

insertAdjacentText( )

insertBefore( )

isSupported( )

mergeAttributes( )

normalize( )

releaseCapture( )

removeAttribute( )

removeAttributeNode( )

removeAttributeNS( )

removeBehavior( )

removeChild( )

removeEventListener( )

removeExpression( )

removeNode( )

replaceAdjacentText( )

replaceChild( )

replaceNode( )

scrollIntoView( )

setActive( )

setAttribute( )

setAttributeNode( )

setAttributeNodeNS( )

setAttributeNS( )

setCapture( )

setExpression( )

swapNode( )

9.5.3. Event Handlers

Events

IE Windows

IE Mac

NN

W3C DOM

DOMActivate[13]

n/a

n/a

n/a

2

DOMAttrModified[13]

n/a

n/a

6

2

DOMCharacterDataModified[13]

n/a

n/a

6

2

DOMFocusIn[13]

n/a

n/a

n/a

2

DOMFocusOut[13]

n/a

n/a

n/a

2

DOMNodeInserted[13]

n/a

n/a

6

2

DOMNodeInsertedIntoDocument[13]

n/a

n/a

6

2

DOMNodeRemoved[13]

n/a

n/a

6

2

DOMNodeRemovedFromDocument[13]

n/a

n/a

6

2

DOMSubtreeModified[13]

n/a

n/a

6

2

onactivate

5.5

n/a

n/a

n/a

onafterupdate[14]

4

5

n/a

n/a

onbeforeactivate

6

n/a

n/a

n/a

onbeforecopy

5

n/a

n/a

n/a

onbeforecut

5

n/a

n/a

n/a

onbeforedeactivate

5.5

n/a

n/a

n/a

onbeforeeditfocus

5

n/a

n/a

n/a

onbeforepaste

5

n/a

n/a

n/a

onbeforeupdate[14]

4

5

n/a

n/a

onblur[15]

3

3.01

2

1

oncellchange[16]

5

n/a

n/a

n/a

onclick[15]

3

3.01

2

1

oncontextmenu

5

n/a

n/a

n/a

oncontrolselect

5.5

n/a

n/a

n/a

oncopy

5

n/a

n/a

n/a

oncut

5

n/a

n/a

n/a

ondataavailable[16]

4

n/a

n/a

n/a

ondatasetchanged[16]

4

n/a

n/a

n/a

ondatasetcomplete[16]

4

n/a

n/a

n/a

ondblclick[15]

4

4

3

n/a

ondeactivate

5.5

n/a

n/a

n/a

ondrag

5

n/a

n/a

n/a

ondragend

5

n/a

n/a

n/a

ondragenter

5

n/a

n/a

n/a

ondragleave

5

n/a

n/a

n/a

ondragover

5

n/a

n/a

n/a

ondragstart

5

n/a

n/a

n/a

ondrop

5

n/a

n/a

n/a

onerrorupdate[14]

4

5

n/a

n/a

onfilterchange

4

n/a

n/a

n/a

onfocus[15]

3

3.01

2

1

onfocusin

6

n/a

n/a

n/a

onfocusout

6

n/a

n/a

n/a

onhelp[15]

4

5

n/a

n/a

onkeydown[15]

4

4

4

3

onkeypress[15]

4

4

4

3

onkeyup[15]

4

4

4

3

onlayoutcomplete

5.5

n/a

n/a

n/a

onlosecapture

5

n/a

n/a

n/a

onmousedown[15]

4

4

4

1

onmouseenter

5.5

n/a

n/a

n/a

onmouseleave

5.5

n/a

n/a

n/a

onmousemove[15]

4

4

4

1

onmouseout[15]

3

3.01

2

1

onmouseover[15]

3

3.01

2

1

onmouseup[15]

4

4

4

1

onmousewheel

6

n/a

n/a

n/a

onmove

5.5

n/a

n/a

n/a

onmoveend

5.5

n/a

n/a

n/a

onmovestart

5.5

n/a

n/a

n/a

onpaste

5

n/a

n/a

n/a

onpropertychange

5

n/a

n/a

n/a

onreadystatechange[17]

4

n/a

n/a

n/a

onresize[15]

4

4

4

n/a

onresizeend

5.5

n/a

n/a

n/a

onresizestart

5.5

n/a

n/a

n/a

onrowenter[16]

4

n/a

n/a

n/a

onrowexit[16]

4

n/a

n/a

n/a

onrowsdelete[16]

5

n/a

n/a

n/a

onrowsinserted[16]

5

n/a

n/a

n/a

onscroll[18]

4

4

n/a

n/a

onselectstart

4

4

n/a

n/a

[13] Event type assignable only via the addEventListener( ) method for any node.

[14]Exposed as property for all elements in IE 6, but applies only to elements that support data binding: a, bdo, button, custom, div, frame, iframe, img, input (checkbox, hidden, password, radio, text), label, legend, marquee, rt, ruby, select, span, and textarea.

[15]Shared among all element objects only in recent browsers. Earlier implementations and compatibilities are listed with applicable objects throughout this chapter.

[16]Exposed as property for all elements in IE 6, but applies only to applet, object, and xml elements set for data binding.

[17]Exposed as property for all elements in IE 6, but applies only to applet, document, frame, frameSet, iframe, img, link, object, script, and xml elements unless an HTML behavior is attached to the element.

[18]Exposed as property for all elements in IE 6, but applies only applet, bdo, body, custom, div, embed, map, marquee, object, table, and textarea elements and the window object.

 
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODENN 6 IE n/a DOM 1

Read-only
This set of constants belongs to the root Node object of the W3C DOM, and is therefore inherited by all document-level nodes and elements. Each property corresponds to an integer value associated with the nodeType property of every DOM node. You can use these properties as a more plain-language way to indicate the node type your script is looking for in comparisons or similar operations.

Example

if (myObject.nodeType == document.ELEMENT_NODE) {
    // process as an element here
}

Value

Integer corresponding to DOM node type as follows.

Property nodeTypeValue

ELEMENT_NODE

1

ATTRIBUTE_NODE

2

TEXT_NODE

3

CDATA_SECTION_NODE

4

ENTITY_REFERENCE_NODE

5

ENTITY_NODE

6

PROCESSING_INSTRUCTION_NODE

7

COMMENT_NODE

8

DOCUMENT_NODE

9

DOCUMENT_TYPE_NODE

10

DOCUMENT_FRAGMENT_NODE

11

NOTATION_NODE

12

Default

Constant values (above).

 
accessKeyNN n/a IE 4 DOM 1

Read/Write
This is single character key that either gives focus to an element (in some browsers) or activates a form control or link action. The browser and operating system determine if the user must press a modifier key (e.g., Ctrl, Alt, or Command) with the access key to activate the link. In Windows versions of IE 5 and later and Netscape 6, the Alt key is required and the key is not case-sensitive. For Macintosh versions of IE 5 and later and Netscape 6, the Ctrl modifier key is required to effect the action.

Although listed here as a widely shared property, that isn't strictly the case across all implementations. Netscape 6 (per the W3C DOM) recognizes this property only for the following elements: a, area, button, input, label, legend, and textarea. To this list, IE 4 adds applet, body, div, embed, isindex, marquee, object, select, span, table, and td (but removes label and legend). IE 5 adds every other renderable element, but with a caution. Except for input and other form-related elements, you must also assign a tabindex attribute or tabIndex property value to the IE 5 and later element (even if it's simply a value of zero for all) to let the accelerator key combination bring focus to the element. As of Version 7, Netscape does not alter UI behavior if a script changes the property's value.

Example

document.links[3].accessKey = "n";

Value

Single alphanumeric (and punctuation) keyboard character.

Default

Empty string.

 
all[ ]NN n/a IE 4 DOM n/a

Read-only
Returns an array of all HTML element objects contained by the current element. Items in this array are indexed (zero-based) in source code order. The collection transcends generations of nested elements such that document.all[ ] exposes every element in the entire document. See the all object for a list of this property value's own set of properties and methods.

As with all collections in Internet Explorer, you may use the traditional JavaScript array syntax (with square brackets around the index value) or IE's JScript alternative (with parentheses around the index value). If you are aiming for cross-browser deployment for collections that are available on both platforms, use the square brackets.

Unless you develop strictly for IE browsers, consider migrating to W3C DOM references via document.getElementById( ), implemented in IE 5 and later and Netscape 6.

Syntax

object.all(index).objectPropertyOrMethod
object.all[index].objectPropertyOrMethod
object.all("elementID").objectPropertyOrMethod
object.all["elementID"].objectPropertyOrMethod
object.all.elementID.objectPropertyOrMethod

Example

var inpVal = document.all.first_name.value;

Value

Array (collection) of element object references in HTML source code order.

Default

Current document's model.

 
attributes[ ]NN 6 IE 5 DOM 1

Read-only
Returns a named node map object, which resembles an array (collection) of attribute objects (W3C DOM type Attr), but also has some methods of its own to facilitate accessing a member of this array. IE's attributes array contains entries for all attributes of the element's internal DTD, plus any custom (expando) attributes explicitly set in the HTML source code in IE 6. Scripted changes to the element's attributes or their values are not reflected in this array.

For Netscape 6, the attributes array contains entries only for those attributes explicitly defined in the HTML source code for the element, including custom attributes. Scripted changes to attributes (additions or deletions) or their values are reflected in the attribute objects referenced by the attributes array.

In lieu of the named node map object methods, you may access individual attribute objects via standard JavaScript array syntax. By and large, however, it is far more convenient to access HTML element attribute values for scripting purposes either via their reflection as element object properties or via the element's getAttribute( ) and setAttribute( ) methods. For W3C DOM details (which are useful for XML document parsing), see the Attr and NamedNodeMap objects for properties and methods of these objects.

Example

var ldAttr = document.getElementById("myImg").attributes.getNamedItem("longdesc");

Value

Array (collection) of attribute object references in source code (Netscape 6), alphabetical-by-name (IE/Mac), or haphazard (IE/Windows) order.

Default

Current element's model.

 
baseURINN 6 IE n/a DOM 3

Read-only
This is a property of the Node object (proposed for DOM Level 3 Core) that reveals the base URI (full path to the source) from which the node was served. For example, each node copied from an XML document loaded into a document.implementation object reveals its baseURI, which is different from that of the HTML page performing the rendering.

Example

var nodeSrc = myXMLDoc.firstChild.childNodes[14].baseURI;

Value

Full URI string.

Default

Current node's internal value.

 
behaviorUrns[ ]NN n/a IE 5(Win) DOM n/a

Read-only
Provides an array of Uniform Resource Names for all external behaviors (.htc files) associated with the element through style sheet syntax. Perhaps for security reasons, the strings entries of this array are always empty.

Example

var htcCount = document.getElementById(elementID).behaviorUrns.length;

Value

Array of (empty) strings.

Default

Array of length 0.

 
canHaveChildrenNN n/a IE 5(Win) DOM n/a

Read-only
Specifies whether the current element may act as a container of other elements. The property value is based on IE for Windows built-in HTML DTDs, which define several elements (such as <br>) that may not have child nodes inserted into them.

Example

if (elementRef.canHaveChildren) {
    // statements to insert or append child elements
}

Value

Boolean value: true | false.

Default

Element-specific.

 
canHaveHTMLNN n/a IE 5.5(Win) DOM n/a

Read-only and Read/Write
Specifies whether the current element may act as a container of other content with HTML markup. The property reports identical information as canHaveChildren for regular HTML elements. For IE HTML Components (defined in an XML-based .htc file), the property is read/write, and directs the browser how to treat the custom element defined by the component.

Example

if (elementRef.canHaveHTML) {
    // statements to insert content with HTML markup
}

Value

Boolean value: true | false.

Default

Element-specific.

 
childNodes[ ]NN 6 IE 5 DOM 1

Read-only
This is a property of the W3C DOM Node object that consists of an array of references to all child nodes (a node list) in the next deeper level of the node hierarchy (whether part of the document node tree or free-standing document fragments not yet inserted into the document tree). To reach more deeply nested nodes, you must access the childNodes array of each child node of the current node. A vital property for walking through a node tree. See the NodeList object for the properties and methods of this kind of array.

Example

for (var i = 0; i < nodeRef.childNodes.length; i++) {
    if (nodeRef.childNodes[i].nodeType == document.ELEMENT_NODE) {
        // operate on an element
    }
}

Value

Array of node object references.

Default

Array of length zero.

 
children[ ]NN n/a IE 4 DOM n/a

Read-only
Returns an array of all first-level HTML element objects contained by the current element. This collection differs from the all[ ] collection in that it contains references only to the immediate children of the current element (whereas the all[ ] collection transcends generations). For example, document.body.children[ ] might contain a form, but no reference to form elements nested inside the form. Items in this array are indexed (zero-based) in source code order. In contrast to the childNodes[ ] array, the scope of this property is the element, not the node. See the children object.

Example

for (var i = 0; i < elementRef.children.length; i++) {
    if (elementRef.children[i].tagName == "FORM") {
        // operate on a form element
    }
}

Value

Array of element object references.

Default

Array of length zero.

 
citeNN 6 IE 6 DOM 1

Read/Write
This property (along with dateTime) is shared among all phrase element objects in IE 6, but in truth, it officially belongs only to the blockquote, quote, del, and ins element objects (see those element descriptions in
Chapter 8 for details on the corresponding attribute in the context of the element). Because the property is shared by four objects, Microsoft may have found it more convenient to implement the property internally for a larger related set of HTML element objects. Or it may be a mistake. Whatever the reason, do not expect this property in as many element objects as IE 6 exposes.

Value

Any valid URL to a document on the World Wide Web, including absolute or relative URLs.

Default

Empty string.

 
classNameNN 6 IE 4 DOM 1

Read/Write
This is an identifier generally used to associate an element with a style sheet rule defined for a class selector. You can alter the class association for an element by script. If the document includes an alternate class selector and style rule, adjusting the element's className property can provide a shortcut for adjusting many style properties at once.

Example

document.getElementById("elementID").className = "altHighlighted";

Value

Case-sensitive string. Multiple class names are space-delimited within the string.

Default

Empty string.

 
clientHeight, clientWidthNN 7 IE 4 DOM n/a

Read-only
Broadly speaking, these provide the height and width of the element's content, but with minor variations with respect to element padding among various operating system versions of IE and compatibility modes controlled by the DOCTYPE declaration. Not available for all element types in IE for Macintosh. For Netscape 7, values are zero except when an element's content overflows the viewable area, in which case the values reveal the dimensions of the viewable area (e.g., the browser window's content region for the document.body element). See the
Section 9.2 at the beginning of this chapter for details.

Example

var midHeight = document.body.clientHeight/2;

Value

Integer pixel value.

Default

0

 
clientLeft, clientTopNN n/a IE 4 DOM n/a

Read-only
Broadly speaking, these provide the left and top coordinates of the element's content within the box that includes the element's padding, but with minor variations among various operating system versions of IE. Not available for all element types in IE for Macintosh. See the
Section 9.2 at the beginning of this chapter for details. More useful information for inline element positioning generally comes from the offsetLeft and offsetTop properties (including Netscape 6). For CSS-positioned elements (including changing an element's position), use style object properties, such as left and top, and (in IE only) pixelLeft and pixelTop.

Value

Integer pixel value.

Default

0

 
contentEditableNN n/a IE 5.5(Win) DOM n/a

Read/Write
Controls whether the element is editable by the user via the IE for Windows live content-editing facilities. User changes are not preserved on the server without intervention by the server, usually via client-side script capture of modified content and submission via form. Scripts should alter the appearance of an element (border, background color, etc.) when in edit mode to highlight the mode for the user. By default, all child elements inherit the edit mode setting of an element. See the onmove event handler in
Chapter 10 for an extended example.

Example

document.getElementById("elementID").contentEditable = "true";

Value

String constant: false | inherit | true.

Default

inherit

 
currentStyleNN n/a IE 5 DOM n/a

Read-only
Returns a style object with properties that reflect the effective values being applied to the element. This property takes into account style sheet rules defined in a style element, imported from external style sheet files, and inline style attributes. Because the style property reflects only inline style attributes, the currentStyle property is more valuable for reading initial values after a document loads. To modify style attributes, you can use the element's style object properties. For similar capabilities in Netscape 6, see the window.getComputedStyle( ) method.

Example

var currSize = document.getElementById("elementID").currentStyle.fontSize;

Value

style object reference.

Default

The effective style object.

 
dateTimeNN 6 IE 6 DOM 1

Read/Write
This property (along with cite) is shared among all phrase element objects in IE 6, but in truth, it officially belongs only to the blockquote, quote, del, and ins element objects (see those element descriptions in
Chapter 8 for details on the corresponding attribute in the context of the element). Because the property is shared by four objects, Microsoft may have found it more convenient to implement the property internally for a larger related set of HTML element objects. Or it may be a mistake. Whatever the reason, do not expect this property in as many element objects as IE 6 exposes.

Value

Date string.

Default

Empty string.

 
dirNN 6 IE 5 DOM 1

Read/Write
Indicates the direction of character rendering for the element's text whose characters are not governed by inherent directionality according to the Unicode standard and default browser language system. Character rendering is either left-to-right or right-to-left.

Value

ltr | rtl (case insensitive string).

Default

ltr

 
disabledNN 6 IE 4 DOM 1

Read/Write
Specifies whether the element is available for user interaction. When set to true, the element cannot receive focus or be modified by the user, and it typically appears grayed out on the page. This property is available for all HTML element objects in IE 5.5 for Windows and later. For IE 4 and IE 5, it applies only to form controls, while Netscape 6 and later recognize the property for form controls and the style element object. A disabled form control's name/value pair is not submitted with its form.

Example

document.getElementById("myButton").disabled = true;

Value

Boolean value: true | false.

Default

false

 
documentNN n/a IE 4 DOM n/a

Read-only
Returns a reference to the document object that contains the current element. Potentially helpful for functions that act on object references retrieved from event properties or passed as ID strings. The corresponding W3C DOM property is ownerDocument.

Example

var currDoc = document.getElementById("elementID").document;

Value

document object reference.

Default

The current document object.

 
filters[ ]NN n/a IE 4 DOM n/a

Returns an array of all filter objects contained by the current element. Applies only to the following element objects: bdo, body, button, div, fieldset, img, input, marquee, rt, ruby, span, table, td, textarea, and th. See the filter object for referencing syntax.

Value

Array of filter object references.

Default

Array of length zero.

 
firstChild, lastChildNN 6 IE 5 DOM 1

Read-only
Return a reference to the first or last child node (respectively) of the current element node. Most commonly, these child nodes are text nodes nested inside an element. For a simple element containing only one text node, both properties return a reference to the same text node. More complex constructions, such as tr elements, can have other element nodes (td elements) as their child nodes, but some browsers may turn source code carriage returns between elements into text nodes. Therefore, it's a good idea to validate the type of node returned by either property before acting on it.

Example

if (document.getElementById("elementID").firstChild.nodeType == 3) {
    // process as a text node
}

Value

Node object (including text node, HTML element node, etc.) reference.

Default

null

 
hideFocusNN n/a IE 5.5(Win) DOM n/a

Read/Write
Specifies whether the browser should display a dotted focus rectangle around the element if it has focus. The element continues to be able to receive focus if it is focusable by default or has the tabindex attribute set. When this property is set to true, there is no visual clue about the focus state.

Example

document.getElementById("elementID").hideFocus = true;

Value

Boolean value: true | false.

Default

false

 
idNN 6 IE 4 DOM 1

Read/Write
Specifies a unique identifier that distinguishes this element from all the rest in the document. The value of this property is most often used to assemble references to elements, but you can loop through all elements to see if there is a match of an id value. It is generally not a good idea to change this property's value for an element already in the document tree. But if a script creates a new element object (via the document.createElement( ) method, for instance), it can assign a unique identifier to this object's id property, and then add the element to the document tree.

Example

var headID = document.getElementsByTagName("head")[0].id;

Value

String.

Default

Empty string.

 
innerHTMLNN 6 IE 4 DOM n/a

Read/Write
Indicates the rendered text and HTML tags (i.e., all source code) between the start and end tags of the current element. A change to this property that includes HTML tags is rendered through the HTML parser, as if the new value were part of the original source code. You may change this property only after the document has fully loaded. Changes to the innerHTML property are not reflected in the source code when you view the source in the browser. This property is not supported in many objects in the Macintosh version of IE 4.

Netscape 6 supports this property as a convenience, even though the W3C DOM does not. Assigning a string lacking HTML tags to the innerHTML property has the same effect as assigning the string to the IE-only innerText property. In IE, you can read or write the source code that includes the element's tags via the outerHTML property.

Example

document.getElementById("elementID").innerHTML = "How <i>now</i> brown cow?";

Value

String that may or may not include HTML tags.

Default

Empty string.

 
innerTextNN n/a IE 4 DOM n/a

Read/Write
Indicates the rendered text (but not any tags) of the current element. If you want the rendered text as well as any nested HTML tags, see innerHTML. Any changes to this property are not rendered through the HTML parser, meaning that any HTML tags you include are treated as displayable text content only. You may change this property only after the document has fully loaded. Changes to the innerText property are not reflected in the source code when you view the source in the browser. This property is not supported in many objects in the Macintosh version of IE 4.

Example

document.getElementById("elementID").innerText = "How now brown cow?";

Value

String.

Default

Empty string.

 
isContentEditableNN n/a IE 5.5(Win) DOM n/a

Read-only
Specifies whether the current element has IE/Windows user editing engaged. Reveals the actual editing state as either explicitly set for the element or inherited from its ancestor tree.

Example

if (document.getElementById("elementID").isContentEditable) {
    // process the editable element
}

Value

Boolean value: true | false.

Default

false

 
isDisabledNN n/a IE 5.5(Win) DOM n/a

Read-only
Specifies whether the current element is disabled. Reveals the actual disabled state as either explicitly set for the element or inherited from its ancestor tree.

Example

if (document.getElementById("elementID").isDisabled) {
    // process the disabled element
}

Value

Boolean value: true | false.

Default

false

 
isMultiLineNN n/a IE 5.5(Win) DOM n/a

Read-only
Specifies whether the current element allows content to extend across multiple lines. Most text containers allow multiple lines, but other kinds of elements, such as a text input element are restricted to single line rendering.

Example

if (document.getElementById("elementID").isMultiLine) {
    // process the element as a potential multiple-line element
}

Value

Boolean value: true | false.

Default

Element default.

 
isTextEditNN n/a IE 4 DOM n/a

Read-only
Specifies whether the element can be used to create an IE/Windows TextRange object (via the createTextRange( ) method). Only body, button, text type input, and textarea elements are permitted to have text ranges created for their content.

Example

if (document.getElementById("elementID").isTextEdit) {
    var rng = document.getElementById("elementID").createTextRange( );
}

Value

Boolean value: true | false.

Default

Element default.

 
langNN 6 IE 4 DOM 1

Read/Write
Indicates the written language being used for the element's attribute and property values. Other applications and search engines might use this information to aid selection of spellchecking dictionaries and creating indices.

Example

document.getElementById("elementID").lang = "de";

Value

Case-insensitive language code.

Default

Browser default.

 
languageNN n/a IE 4 DOM n/a

Read/Write
Indicates the scripting language for script statements defined in the element.

Example

document.getElementById("elementID").language = "vbscript";

Value

Case-insensitive scripting language name as string: javascript | jscript | vbs | vbscript.

Default

jscript

 
lastChild

See firstChild.

 
localName, namespaceURI, prefixNN 6 IE n/a DOM 2

Read-only
These three properties apply primarily to XML document elements with tags that are defined with the help of XML namespaces. A simplified example of such a document follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<results xmlns:libBook="http://catalog.umv.edu/schema">
<libBook:title libBook:rareBooks="true">De Principia</libBook:title>
</results>

The properties reveal details about the element's naming characteristics. A localName is the equivalent of the nodeName property of the element, that is, the tag name within the scope of the entire document, even if the tag name is reused by another element originating from another namespace. The prefix, however, links the element with a prefix name that is normally defined with an xmlns attribute of a container in the XML document. This helps your script identify the namespace to which the element is associated. A further binding is revealed through the namespaceURI property, which returns the URI string assigned to the xmlns attribute of a container element. Although all three properties belong to the Node object, their values are null (or, rather, should be null, but in Netscape 6 are empty strings) for node types other than element and attribute nodes.

Example

var allTitles = document.getElementsByTagName("title");
for (var i = 0; i < allTitles.length; i++) {
    if (allTitles[i].prefix == "libBook" &&
        allTitles[i].namespaceURI.indexOf("catalog.umv.edu") != -1) {
        // process title elements from the desired namespace here
    }
}

Value

Strings.

Default

For localName, the element's tag name. For others, an empty string.

 
namespaceURI

See localName.

 
nextSibling, previousSiblingNN 6 IE 5 DOM 1

Read-only
Return a reference to the next or previous node (respectively) in the document tree at the same nested level as the current node. If there is no node in the position indicated by the property name, the property returns null. For a lone text node inside an element node, both properties return null. Node sequence is determined intially by source code order, but script changes to the document tree are reflected in the nodes returned by these properties.

Example

var nextNode = document.getElementById("elementID").nextSibling;

Value

Node object (including text node, HTML element node, etc.) reference.

Default

null

 
nodeNameNN 6 IE 5 DOM 1

Read-only
Returns a string that identifies the name of the node as influenced by the node type. For element and attribute node types, the property returns the tag name and attribute name, respectively. For many other kinds of nodes, which have no inherent label associated with them, the nodeName property returns a fixed string indicating the node type, such as #text for a text node and #document for the root document node. For elements, the property returns the same string value as the element object's tagName property. Note that browsers through IE 6 and Netscape 7 return element tag strings in all uppercase, regardless of source code style or DOCTYPE specification.

Example

if (document.getElementById("elementID").nextSibling.nodeName == "#text") {
    // process as a text node
}

Value

Fixed string for #cdata-section, #document, #document-fragment, and #text nodes; variable string for attribute, element, and other node types.

Default

Node-specific.

 
nodeTypeNN 6 IE 5 DOM 1

Read-only
Returns an integer that corresponds to a node type as specified in the W3C DOM. This is the preferred property to use to test a node object for its type (rather than the nodeName property values). Every node type has a value, but not all browsers that support the nodeType property support all node types as objects. The integer values have corresponding constants associated with them, which you can use to make more verbose, but easier-to-read script comparisons for node type processing (see the ATTRIBUTE_NODE property earlier in this chapter). Note that there is no way to distinguish element types (e.g., root Element node versus an HTMLElement node) via the nodeType property. Also note that IE 6 in Windows erroneously reports a DOCTYPE element as a comment node type.

Example

if (document.getElementById("elementID").firstChild.nodeType == 1) {
    // process as an element
}

Value

Integer values according to the following table.

Value

Node type

W3C DOM

IE/Windows

IE/Mac

NN

1

ELEMENT_NODE

1

5

5

6

2

ATTRIBUTE_NODE

1

6

5

6

3

TEXT_NODE

1

5

5

6

4

CDATA_SECTION_NODE

1

n/a

n/a

n/a

5

ENTITY_REFERENCE_NODE

1

n/a

n/a

na/

6

ENTITY_NODE

1

n/a

n/a

n/a

7

PROCESSING_INSTRUCTION_NODE

1

n/a

n/a

n/a

8

COMMENT_NODE

1

6

5

6

9

DOCUMENT_NODE

1

5

5

6

10

DOCUMENT_TYPE_NODE

1

n/a

n/a

6

11

DOCUMENT_FRAGMENT_NODE

1

n/a

n/a

6

12

NOTATION_NODE

1

n/a

n/a

n/a

Default

Node-specific.

 
nodeValueNN 6 IE 5 DOM 1

Read/Write
Although the nodeValue property belongs to every node type, it is particularly helpful for text nodes because the property provides read/write access to the actual rendered text content of a text node. This property provides the W3C DOM canonical access to reading and modifying the text node nested inside an element, assuming your script addresses the nodeValue property of, say, an element's firstChild node. The property returns null for element nodes, so do not think of it as a pure replacement for the innerText or innerHTML convenience properties. The property returns the value assigned to an attribute when used with an attribute node.

Example

document.getElementById("elementID").firstChild.nodeValue = "New Text!";

Value

String, although IE for Windows may return an attribute node's value as a Number data type if the value consists of a numeric value. You should always assign a string to this property.

Default

Empty string.

 
offsetHeight, offsetWidthNN 6 IE 4 DOM n/a

Read-only
Broadly speaking, provide the height and width of the element's content, but with minor variations with respect to element borders and padding among various operating system versions of IE and compatibility modes controlled by the DOCTYPE declaration. The trend is to include the measure of borders and padding, but not margins in these values. Implemented in Netscape 6 as a convenience, even though not part of the W3C DOM. See the
Section 9.2 at the beginning of this chapter for details.

Example

var midpoint = document.getElementById("elementID").offsetWidth/2;

Value

Integer pixel count.

Default

Element-specific.

 
offsetLeft, offsetTopNN 6 IE 4 DOM n/a

Read-only
Broadly speaking, provide the left and top coordinates of the element's box, but with minor variations with respect to the coordinate system context (vis-à-vis the offsetParent element) influenced by various operating system versions of IE and compatibility modes controlled by the DOCTYPE declaration. Implemented in Netscape 6 as a convenience, even though not part of the W3C DOM. See the
Section 9.2 at the beginning of this chapter for details. For positioned elements, you should rely more on the element's style properties that control location in the document or browser viewing space.

Example

if (document.getElementById("elementID").offsetLeft <= 20 &&
document.getElementById("elementID").offsetTop <=40) {
    ...
}

Value

Integer pixel count.

Default

Element-specific.

 
offsetParentNN 6 IE 4 DOM n/a

Read-only
Returns a reference to the object that is the current element's offset positioning context. For most elements on an IE page and all elements in a Netscape 6 page, this is the body object. But elements in IE that are wrapped in div elements or are cells of a table have other parents. Moreover, for complex nested elements, you will find wide variations in the object returned by this property, depending on browser version. For example, the offsetParent property of a td element is the next outermost tr element in IE 4 for Windows, and the table element for later versions of IE for Windows and all versions of IE for the Macintosh. Netscape 6 still regards the body element as the offsetParent of the td element. See the
Section 9.2 at the beginning of this chapter for an example of using this property to calculate the precise position of an inline element.

Example

var containerLeft = document.getElementById("elementID")offsetParent.offsetLeft;

Value

Object reference.

Default

body object.

 
outerHTMLNN n/a IE 4 DOM n/a

Read/Write
Indicates the rendered text and HTML tags (i.e., all source code), including the start and end tags, of the current element. If you want only the rendered text, see outerText. For the source code that excludes the current element's tags, see innerHTML. A change to this property that includes HTML tags is rendered through the HTML parser, as if the new value were part of the original source code. You may change this property only after the document has fully loaded, and, in the process, you can even change the type of element it is or replace the element with straight text content. Changes to the outerHTML property are not reflected in the source code when you view the source in the browser. To add to existing HTML, see the insertAdjacentHTML( ) method. This property is not supported in many objects in the Macintosh version of IE 4. The W3C DOM equivalent requires extensive manipulation of node-level objects, as shown in
Chapter 5.

Example

document.getElementById("elementID").outerHTML = 
    "<acronym id="quotes">NI<i>M</i>BY</acronym>";

Value

String that may or may not include HTML tags.

Default

Empty string.

 
outerTextNN n/a IE 4 DOM n/a

Read/Write
Indicates the rendered text (but not any tags) of the current element. If you want the rendered text as well as the element's HTML tags, see outerHTML. Any changes to this property are not rendered through the HTML parser, meaning that any HTML tags you include are treated as displayable text content only. You may change this property only after the document has fully loaded. Changes to the outerText property are not reflected in the source code when you view the source in the browser. This property is not supported in many objects in the Macintosh version of IE 4.

Example

document.getElementById("elementID").outerText = "UNESCO";

Value

String.

Default

Empty string.

 
ownerDocumentNN 6 IE 5(Mac)/6(Win) DOM 1

Read-only
Returns a reference to the document object that contains the current node. Potentially helpful for functions that act on object references retrieved from event properties or passed as ID strings. The corresponding IE property is document.

Example

var currDoc = document.getElementById("elementID").ownerDocument;

Value

document object reference.

Default

The current document object.

 
parentElementNN n/a IE 4 DOM n/a

Read-only
Returns a reference to the next outermost element in the HTML containment hierarchy. An element's HTML parent is not necessarily the same as the object returned by the offsetParent property. The parentElement concerns itself strictly with source code containment, while the offsetParent property looks to the next outermost element that is used as the coordinate system for measuring the location of the current element. For example, if the main document contains a p element with an em element nested inside, the em element has two parents. The p element is the returned parentElement value (due to the HTML source code containment), while the body element is the returned offsetParent value (due to coordinate space containment).

You can jump multiple parent levels by cascading parentElement properties, as in:

document.getElementById("elementID").parentElement.parentElement;

You can then use references to access a parent element's properties or methods.

The corresponding property for the W3C DOM is parentNode.

Example

document.getElementById("elementID").parentElement.style.fontSize = "14pt";

Value

Element object reference.

Default

Element-specific.

 
parentNodeNN 6 IE 5 DOM 1

Read-only
Returns a reference to the next outermost node (usually an element) that acts as a container to the current node in the document tree. The relationship between the current node and its parent is purely structural, and is not concerned with positioning context. A parent node is one that completely encases the current node—not to be confused with sibling nodes, which, at best, reside on just one side of the current node. You can use the same cascading tricks as shown for the IE parentElement property, but it is hazardous to completely equate results from the element-centric IE-only properties with results from the W3C DOM node-centric properties (even though recent IE versions support both views of the world).

Example

if (document.getElementById("elementID").parentNode.nodeType == 1) {
    document.getElementById("elementID").parentNode.style.fontSize = "14pt";
}

Value

Element object reference.

Default

Node-specific.

 
parentTextEditNN n/a IE 4 DOM n/a

Read-only
Returns a reference to the next highest element up the HTML containment hierarchy that is of a type that allows a TextRange object to be created with it. This property may have to reach through many levels to find a suitable object. This property always returns null in IE for the Macintosh (through Version 5.1) because of lack of support for text ranges.

Example

var rangeElement = document.getElementById("elementID").parentTextEdit;
var rng = rangeElement.createTextRange( );

Value

Element object reference.

Default

body object.

 
prefix

See localName.

 
previousSibling

See nextSibling.

 
readyStateNN n/a IE 4 DOM n/a

Read-only
Returns the current download status of the object's content. If a script (especially one initiated by a user event) can perform some actions while the document is still loading, but must avoid other actions until the entire page has loaded, this property provides intermediate information about the loading process. You should use its value in condition tests. The value of this property changes during loading as the loading state changes. Each change of the property value fires an onReadyStateChange event (the event does not bubble).

When introduced with IE 4, the property was available for only the document, embed, img, link, object, script, and style objects. IE 5 expanded coverage to all HTML element objects.

Example

if (document.readyState == "loading") {
    //statements for alternate handling while loading
}

Value

For all but the object element, one of the following values (as strings): uninitialized | loading | loaded | interactive | complete. Some elements may allow the user to interact with partial content, in which case the property may return interactive until all loading has completed. Not all element types return all values in sequence during the loading process. The object element returns numeric values for these five states. They range from 0 (uninitialized) to 4 (complete).

Default

None.

 
recordNumberNN n/a IE 4 DOM n/a

Read-only
Used with IE data binding, returns an integer representing the record within the data set that generated the element (i.e., an element whose content is filled via data binding). Values of this property can be used to extract a specific record from an Active Data Objects (ADO) record set (see recordset property). Although this property is defined for all IE element objects, the other properties related to data binding belong to a subset of elements.

Example

<script for="tableTemplate" event="onclick">
    myDataCollection.recordset.absoluteposition = this.recordNumber;
    ...
</script>

Value

Integer.

Default

null

 
runtimeStyleNN n/a IE 5 DOM n/a

Read/Write
Returns a style object whose individual style properties convey values only if they are explicitly set via the regular style sheet processes. Unlike the currentStyle object, system default style sheet properties are not reflected. You can set individual style properties of this runtimeStyle object, but doing so transcends (some might say violates) normal cascading precedence. Any property you assign by script overrides all other settings for that style property governing that element, including values assigned to the element tag's style attribute and style property. For example, if you assign the value red to an element's style.color property, and assign the value green to the same element's runtimeStyle.color property, the element's text appears in green, even though the more specific style.color property still preserves the red value. At that point the element's currentStyle.color property also returns green, because that is the effective style governing the element at that instant.

You can use the runtimeStyle object to assign multiple style properties by reassigning a CSS syntax rule to the runtimeStyle.cssText property. Assign an empty string to the cssText property to remove all in-line attribute values, allowing the regular style sheet cascade to control the element's effective style.

Example

document.getElementById("elementID").runtimeStyle.cssText = 
  "border: 5px blue solid";

Value

style object reference.

Default

The effective style object and its explicitly defined style attribute values.

 
scopeName, tagUrnNN n/a IE 5(Win) DOM n/a

Read-only
For custom elements employing XML namespaces, the scopeName property returns the identifier that associates the tag name with a namespace that is defined elsewhere in the document via the xmlns attribute. All plain HTML elements return a value of HTML for this property. The tagUrn property returns the URI specified for the namespace. The corresponding properties in the W3C DOM are prefix and namespaceURI.

Example

var allTitles = document.getElementsByTagName("title");
for (var i = 0; i < allTitles.length; i++) {
    if (allTitles[i].scopeName == "libBook" &&
        allTitles[i].tagUrn.indexOf("catalog.umv.edu") != -1) {
        // process title elements from the desired namespace here
    }
}

Value

Strings.

Default

HTML for scopeName; empty string for tagUrn.

 
scrollHeight, scrollWidthNN 7 IE 4 DOM n/a

Read-only
Originally implemented in IE 4 for elements that either scrolled or influenced an element's scroll (body, button, caption, div, fieldset, legend, marquee, and textarea), these properties return the pixel dimensions of an element, including elements that are larger than the viewable area in the browser window. This is in contrast to the clientHeight and clientWidth properties for scrollable elements, which return dimensions of only visible portions of the element. IE for the Macintosh, however, interprets the intent of the scroll- properties differently, returning the dimensions of the visible portion.

Starting in IE 5 for Windows, all HTML elements have these properties, and the values for nonscrolling elements are the same as the offsetHeight and offsetWidth properties. Netscape 7 implements these properties for all elements, returning the height and width of the element, whether or not it's in view. The important point is that for key elements, such as the body, the properties mean different things and can disrupt cross-platform operation.

Example

var midPoint = document.body.scrollHeight/2;

Value

Positive integer or zero.

Default

None.

 
scrollLeft, scrollTopNN 7 IE 4 DOM n/a

Read/Write
Provide the distance in pixels between the actual left or top edge of the element's physical content and the left or top edge of the visible portion of the content. Setting these properties allows you to use a script to adjust the scrolling of content within a scrollable container, such as text in a textarea element or an entire document in the browser window or frame. When the content is not scrolled, both values are zero. Setting the scrollTop property to 15 scrolls the document upward by 15 pixels in the window; the scrollLeft property is unaffected unless explicitly changed. The property values change as the user adjusts the scrollbars. This is important for some event-driven positioning tasks in IE for Windows because the coordinate system for event offset measurements are with respect to the visible area of a page in the browser window. You must add document.body scrolling factors to align event coordinates with body content positions (see the element dragging example in
Chapter 6). Starting with IE 5 for Windows, the scrollLeft and scrollTop properties are available for all HTML element objects, but values for unscrollable elements are zero.

Example

document.body.scrollTop = 40;

Value

Positive integer or zero.

Default

0

 
sourceIndexNN n/a IE 4 DOM n/a

Read-only
Returns the zero-based index of the element among all elements in the document. Elements are numbered according to their source code order, with the first element given a sourceIndex of zero.

Example

var whichElement = document.getElementById("elementID").sourceIndex;

Value

Positive integer or zero.

Default

Element-specific.

 
styleNN 6 IE 4 DOM 2

Read/Write
Indicates the style object associated with the element, as set by values explicitly assigned to the element's style attribute in the tag. In W3C DOM object terminology, this object more specifically is called a CSSStyleDeclaration object. For most style sheet scripting purposes, however, you can treat the IE and Navigator style object as similar objects. This property is the gateway to reading and writing individual style sheet property settings for an element. To read the effective style sheet properties governing an element (including imported style sheet attributes), see the currentStyle property earlier in this chapter (for IE) and the window.getComputedStyle( ) method (for Netscape 6).

Example

document.getElementById("elementID").style.fontSize = "14pt";

Value

style object.

Default

None.

 
tabIndexNN 6 IE 4 DOM 1

Read/Write
This is a number that indicates the sequence of this element within the tabbing order of all focusable elements in the document. Tabbing order follows a strict set of rules. Elements that have values other than zero assigned to their tabIndex properties are first in line when a user starts tabbing in a page. Focus starts with the element with the lowest tabIndex value and proceeds in order to the highest value, regardless of physical location on the page or in the document. If two elements have the same tabIndex values, the element that comes earlier in the document receives focus first. Next come all elements that either don't support the tabIndex property or have the value set to zero. These elements receive focus in the order in which they appear in the document.

The W3C DOM and Netscape 6 limit the tabIndex property to the following element objects: a, area, button, input, object, select, textarea. To this list, IE 4 adds applet, body, div, embed, isindex, marquee, span, table, and td. IE 5 adds every other renderable element. A negative value in IE (only) removes an element from tabbing order entirely.

Links and anchors cannot be tabbed to with the Mac version of IE 4, so the tabIndex property for a element objects is ignored in that version.

Example

document.getElementById("link3").tabIndex = 6;

Value

Integer.

Default

0

 
tagNameNN 6 IE 4 DOM 1

Read-only
Returns the name of the tag of the current element. Tag names are always returned in all uppercase letters for purposes of string comparisons, regardless of source code style or DOCTYPE declaration.

Example

var theTag = document.getElementById("elementID").tagName;

Value

String.

Default

Element-specific.

 
tagUrn

See scopeName.

 
titleNN 6 IE 4 DOM 1

Read/Write
Provides an advisory description of the element. When the element is one that has a physical presence on the page, the browser renders the value of this property as a floa