DekGenius.com
Team LiB   Previous Section   Next Section
HTMLElement the superclass of all HTML elements

Availability

JavaScript 1.2

Synopsis

HTMLElement is the superclass of all classes that represent HTML elements. Therefore, HTMLElement objects are used in many contexts in client-side JavaScript and are available in all of the following ways:

document.images[i]
document.links[i]
document.anchors[i]
document.forms[i]
document.forms[i].elements[j]
document.elementName
document.formName.elementName
document.all[i]

Properties

all[] [IE 4]

The complete list of elements contained within this element, in source order. This property behaves exactly like the Document.all[] property. See the Document.all[] reference page.

children[] [IE 4]

The elements that are direct children of this element.

className [IE 4, Netscape 6]

A read/write string that specifies the value of the class attribute of an element. This property is used in conjunction with Cascading Style Sheets.

document [IE 4]

A reference to the containing Document object.

id [IE 4, Netscape 6]

A read/write string that specifies the value of the id attribute of an element. This property is used to assign a unique name to an element.

innerHTML [IE 4, Netscape 6]

A read/write string that specifies the HTML text that is contained within the element, not including the opening and closing tags of the element itself. Setting this property replaces the content of the element with the specified HTML text. Note that you cannot set this property while the document is loading.

innerText [IE 4]

A read/write string that specifies the plain text contained within the element, not including the opening and closing tags of the element itself. Setting this property replaces the content of the element with unparsed plain text. Note that you cannot set this property while the document is loading.

lang [IE 4, Netscape 6]

A read/write string that specifies the value of the lang HTML attribute of the element.

offsetHeight [IE 4]

The height, in pixels, of the element and all its content.

offsetLeft [IE 4]

The X-coordinate of the element relative to the offsetParent container element.

offsetParent [IE 4]

Specifies the container element that defines the coordinate system in which offsetLeft and offsetTop are measured. For most elements, offsetParent is the Document object that contains them. However, if an element has a dynamically positioned container, the dynamically positioned element is the offsetParent. Similarly, table cells are positioned relative to the row in which they are contained.

offsetTop [IE 4]

The Y-coordinate of the element, relative to the offsetParent container element.

offsetWidth [IE 4]

The width, in pixels, of the element and all its content.

outerHTML [IE 4]

A read/write property that specifies the HTML text of an element, including its start and end tags. Setting this property to a string of HTML text completely replaces element and its contents. Note that you cannot set this property while the document is loading.

outerText [IE 4]

A read/write property that specifies the plain text of an element, including its start and end tags. Setting this property completely replaces element and its contents with the specified plain text. Note that you cannot set this property while the document is loading.

parentElement [IE 4]

The element that is the direct parent of this element. This property is read-only.

sourceIndex [IE 4]

The index of the element in the Document.all[] array of the document that contains it.

style [IE 4, Netscape 6]

The inline CSS style attributes for this element. Setting properties of this Style object changes the display style of the element. See Chapter 18.

tagName [IE 4, Netscape 6]

A read-only string that specifies the name of the HTML tag that defined element.

title [IE 4, Netscape 6]

A read/write string that specifies the value of the title attribute of the HTML tag that defined element. Most browsers use this string as a "tool tip" for the element.

Methods

contains( )

Determines whether the element contains a specified element.

getAttribute( )

Gets the value of a named attribute.

handleEvent( )

Passes an Event object to the appropriate event handler.

insertAdjacentHTML( )

Inserts HTML text into the document near this element.

insertAdjacentText( )

Inserts plain text into the document near this element.

removeAttribute( )

Deletes an attribute and its value from the element.

scrollIntoView( )

Scrolls the document so the element is visible at the top or bottom of the window.

setAttribute( )

Sets the value of an attribute of the element.

Event Handlers

onclick

Invoked when the user clicks on the element.

ondblclick

Invoked when the user double-clicks on the element.

onhelp

Invoked when the user requests help. IE 4 only.

onkeydown

Invoked when the user presses a key.

onkeypress

Invoked when the user presses and releases a key.

onkeyup

Invoked when the user releases a key.

onmousedown

Invoked when the user presses a mouse button.

onmousemove

Invoked when the user moves the mouse.

onmouseout

Invoked when the user moves the mouse off the element.

onmouseover

Invoked when the user moves the mouse over an element.

onmouseup

Invoked when the user releases a mouse button.

Description

HTMLElement is the superclass of all JavaScript classes that represent HTML elements: Anchor, Form, Image, Input, Link, and so on. HTMLElement defines event handlers that are implemented by all elements in both IE 4 and Netscape 4. Because The IE 4 document object model exposes all HTML elements in a document, it defines quite a few properties and methods for those elements. Netscape 4 implements none of these IE properties and methods (except handleEvent( ), which is Netscape-specific), but Netscape 6 implements those that have been standardized by the W3C DOM. See the Chapter 25 reference section for complete information on the standard properties and methods of HTML elements.

See Also

Anchor, Form, Image, Input, Link; Chapter 17; Chapter 19; Element, HTMLElement, and Node in the DOM reference section

    Team LiB   Previous Section   Next Section