Aptana Studio ヘルプ > Reference > HTML DOM Level 2

HTMLElement : Element
Return to: HTML DOM Level 2 index

HTMLElement is the parent class of all HTML elements.

Platform Support

IE Mozilla Netscape Opera Safari
3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Constructors

Constructor Action IE Mozilla Netscape Opera Safari
HTMLElement Constructor() : HTMLElement
HTMLElement is the parent class of all HTML elements.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

HTMLElement() : HTMLElement

HTMLElement is the parent class of all HTML elements.

Returns

HTMLElement

Visibility
internal

Inherited Properties

Property Action IE Mozilla Netscape Opera Safari
tagName : String
The tag name for this element
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.3+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/aboutnodes.html

Remarks
Identifies the name of an element in a source document, including any namespace prefix. For example, in the following XML content, tagName value of the outer element (the ]]> element) returns "example1", while the inner element has a tagName value of "test:example2", even though the element name itself, without the namespace prefix is simply "example2".:
]]>
Availability

HTML DOM Level 2|W3C

Properties

Property Action IE Mozilla Netscape Opera Safari
accessKey : String
Character for the hotkey that gives focus to the element.
No Details 4.0+ no no no no
all : Array
Array of all of the elements in the element.
No Details 4.0+ no no no no
align : String
Alignment property for the element. Used for display elements. (e.g. "center")
No Details 4.0+ no no no no
attributes : Array
Array of attributes for the element.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes.html

Availability

HTML DOM Level 1

begin : String
Gets or sets a time delay to lapse before the element starts "playing".
No Details 5.5+ no no no no
behaviorUrns : Array
Array of behaviors attached to the element.
No Details 5.0+ no no no no
canHaveChildren : Boolean
If true, indicates that the element can have child nodes.
No Details 5.0+ no no no no
canHaveHTML : Boolean
If true, indicates that the element can contain HTML tags.
No Details 5.5+ no no no no
childNodes : Array
Array of the child nodes of the element.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/children.html

Availability

HTML DOM Level 1

children : Array
Array of the child nodes of the element.
Show Details 4.0+ no no 8.0+ 1.3+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/children.html

className : String
Name of the CSS class that the element belongs to.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/taginfo.html

Availability

HTML DOM Level 2|W3C

clientHeight : Number
Height of the content of the element (in pixels).
No Details 4.0+ 1.0+ 7.0+ 7.0+ 1.0+
clientLeft : Number
Number of pixels between the offsetLeft property of the element and the start of the content of the element.
No Details 4.0+ 1.9+ no no no
clientTop : Number
Number of pixels between the offsetTop property of the element and the top of the content of the element.
No Details 4.0+ 1.9+ no no no
clientWidth : Number
Width of the content of the element (in pixels).
No Details 4.0+ 1.0+ 7.0+ 7.0+ 1.0+
contentEditable : String
Indicates whether the content of the element is editable. Possible values are "inherit", "true", or "false".
No Details 5.5+ no no no no
currentStyle : Object
Reference to the Style object specifying the styles applied to the element.
Show Details 5.0+ no no no no

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/style.html

dir : String
Direction of the text in the element. Possible values are "ltr" (left-to-right) or "rtl" (right-to-left).
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/taginfo.html

Availability

HTML DOM Level 2|W3C

disabled : Boolean
If true, indicates that the element is disabled.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/stylesheets.html

document : Object
Reference to the parent Document object for the element.
No Details 4.0+ no no no no
filters : Array
Array of Microsoft CSS filters on the element.
No Details 5.5+ no no no no
firstChild : Object
Reference to the first child element of the element, if one exists.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/nodetree.html

Availability

HTML DOM Level 1

hasMedia : Boolean
If true, indicates that the element is an HTML+TIME media element.
No Details 5.5+ no no no no
hideFocus : Boolean
If true, the element does not give any visual cues to indicate when it has focus.
No Details 5.5+ no no no no
id : String
Unique identifier for the element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/taginfo.html

Availability

HTML DOM Level 2|W3C

innerHTML : String
HTML content within the tags of the element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • IE: Buggy on Mac.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/innerhtml.html

innerText : String
Text string enclosed by the tags of the element. Any HTML tags will be interpreted as part of the text string, not as HTML.
Show Details 4.0+ no 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/innerhtml.html

isContentEditable : Boolean
If true, indicates that the user can edit the contents of the element.
No Details 5.5+ no no no no
isDisabled : Boolean
If true, indicates that the element is disabled from user interaction.
No Details 5.5+ no no no no
isTextEdit : Boolean
If true, indicates that a TextRange object can be created using the element.
No Details 4.0+ no no no no
lang : String
Language code for the content of the element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
Availability

HTML DOM Level 2|W3C

language : String
No Details 4.0+ no no no no
lastChild : Object
Reference to the last child element of the element, if it exists.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/nodetree.html

Availability

HTML DOM Level 1

localName : String
Local XML name for the element.
No Details no 1.0+ 6.0+ 7.0+ 1.0+
namespaceURI : String
The XML Namespace URI for the element.
No Details no 1.0+ 6.0+ 7.0+ 1.0+
nextSibling : Object
Reference to the next sibling element of the element.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/nodetree.html

Availability

HTML DOM Level 1

nodeName : String
Name of the element tag.
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.3+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/aboutnodes.html

Remarks
Returns an uppercase tag name.
Availability

HTML DOM Level 1

nodeType : Number
Node type for the element. See Remarks for full explanation.
Show Details 5.5+ 1.0+ 6.0+ 8.0+ 1.3+
  • IE: IE 5.0 on Windows does not assign nodeType attributes. Fixed in IE 5.5.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/aboutnodes.html

Availability

HTML DOM Level 1

nodeValue : String
Value of the element.
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.3+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/aboutnodes.html

Availability

HTML DOM Level 1

offsetHeight : Number
Height of the element (in pixels).
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
See Also

offsetLeft|offsetParent|offsetTop|offsetWidth

offsetLeft : Number
Number of pixels the left edge of the element is offset from the left edge of its parent element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
See Also

offsetHeight|offsetParent|offsetTop|offsetWidth

offsetParent : Object
Reference to the parent object corresponding with the offsetHeight, offsetWidth, offsetLeft, and offsetTop properties.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
See Also

offsetHeight|offsetLeft|offsetTop|offsetWidth

offsetTop : Number
Number of pixels the top edge of the element is offset from the top edge of its parent element.
No Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
offsetWidth : Number
Width of the element (in pixels).
No Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
onactivate : Function
Fires when the element becomes active.
No Details 4.0+ no no no no
onbeforecopy : Function
Fires immediately before the selection is copied to the clipboard.
No Details 4.0+ no no no 1.0+
onbeforecut : Function
Fires immediately before the selection is cut to the clipboard.
No Details 4.0+ no no no 1.0+
onbeforedeactivate : Function
Fires immediately before the element stops being the active element.
No Details 4.0+ no no no no
onbeforeeditfocus : Function
Fires immediately before the element receives focus prior to being edited.
No Details 4.0+ no no no no
onbeforepaste : Function
Fires immediately before the selection is pasted from the clipboard to the element.
No Details 4.0+ no no no 1.0+
onblur : Function
Fires when the element loses focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onclick : Function
Fires when the element is clicked.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
oncontextmenu : Function
Fires when the element is right-clicked and the context menu opens.
No Details 4.0+ no no no 1.0+
oncontrolselect : Function
Fires immediately before the element is selected.
No Details 4.0+ no no no no
oncopy : Function
Fires when the element is copied to the clipboard.
No Details 4.0+ 1.9+ no no 1.0+
oncut : Function
Fires when the element is cut to the clipboard.
No Details 4.0+ 1.9+ no no 1.0+
ondblclick : Function
Fires when the element is double-clicked.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
ondeactivate : Function
Fires when the active element becomes inactive.
No Details 4.0+ no no no no
ondrag : Function
Fires when the element is dragged.
No Details 4.0+ no no no 1.0+
ondragend : Function
Fires when the element is released from being dragged.
No Details 4.0+ no no no 1.0+
ondragenter : Function
Fires when the element has another object dragged onto it that can be dropped on the element.
No Details 4.0+ no no no 1.0+
ondragleave : Function
Fires when an element has an object dragged out of it that could be dropped onto the element.
No Details 4.0+ no no no 1.0+
ondragover : Function
Fires when an element has an object dragged over it that could be dropped onto the element.
No Details 4.0+ no no no 1.0+
ondragstart : Function
Fires immediately before an element is dragged.
No Details 4.0+ no no no 1.0+
ondrop : Function
Fires when an object is dropped onto the element.
No Details 4.0+ no no no 1.0+
onfilterchange : Function
Fires when the CSS Filter of an element changes or finishes transitioning.
No Details 4.0+ no no no no
onfocus : Function
Fires when the element receives focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onhelp : Function
Fires when a user presses the F1 key to activate help.
No Details 4.0+ no no no no
onkeydown : Function
Fires when a user presses down on a key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onkeypress : Function
Fires when a user presses a key or holds down the key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onkeyup : Function
Fires when a user releases a key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onlosecapture : Function
Fires when the element loses mouse capture.
No Details 4.0+ no no no no
onmousedown : Function
Fires when a user clicks down on the mouse button while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseenter : Function
Fires when the mouse pointer enters the element.
Show Details 4.0+ no no no no
Remarks
Differs from onmouseover in that onmouseenter does not bubble and is not cancelable.
onmouseleave : Function
Fires when the mouse pointer leaves the element.
Show Details 4.0+ no no no no
Remarks
Differs from onmouseout in that onmouseleave does not bubble and is not cancelable.
onmousemove : Function
Fires when the mouse moves while the pointer over the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseout : Function
Fires when the mouse pointer moves off of the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseover : Function
Fires when the mouse pointer moves over the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseup : Function
Fires when the user releases the mouse button while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onpaste : Function
Fires when the clipboard contents are pasted onto the element.
No Details 4.0+ 1.9+ no no 1.0+
onpropertychange : Function
Fires when one of the properties of the element changes.
No Details 4.0+ no no no no
onreadystatechange : Function
Fires when the ready state of the element changes.
No Details 4.0+ no no no no
onresize : Function
Fires immediately before an element is about to be resized.
No Details 4.0+ no no no 1.0+
onresizeend : Function
Fires when the element is finished being resized.
No Details 4.0+ no no no no
onresizestart : Function
Fires immediately before a user resizes the element.
No Details 4.0+ no no no no
onselectstart : Function
Fires immediately before the element is selected.
No Details 4.0+ no no no 1.0+
outerHTML : String
HTML mark-up for an element, including start and end tags and any content between the tags.
Show Details 4.0+ no no 8.0+ 1.3+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/innerhtml.html

See Also

innerHTML|outerText

outerText : String
Plain text for an element, including start and end tags.
Show Details 4.0+ no no 8.0+ 1.3+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/innerhtml.html

See Also

outerHTML|innerText

ownerDocument : Object
Reference to the document that contains the element.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/document.html

Availability

HTML DOM Level 1

parentElement : Object
Reference to the direct parent element of the element.
No Details 4.0+ no no no no
parentNode : Object
Reference to the direct parent node of the element, if it exists.
Show Details 4.0+ 1.0+ 6.0+ 4.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/nodetree.html

See Also

parentElement

Availability

HTML DOM Level 1

parentTextEdit : Object
Reference to the closest parent element to the current element that can create a TextRange that contains the current element.
No Details 4.0+ no no no no
prefix : String
Prefix XML name for the element.
No Details no 1.0+ no 4.0+ 1.0+
Reference to the previous sibling element of the element, if it exists.
Show Details 5.0+ 1.0+ 6.0+ 4.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/nodetree.html

Availability

HTML DOM Level 1

readyState : String
Current readiness state of the element. See Remarks for possible values.
Show Details 4.0+ no no no no
Remarks
Valid values are 0 = uninitialized, 1 = open, 2 = sent, 3 = receiving, 4 = loaded.
recordNumber : Number
Record number for the data set that generated the element.
No Details 4.0+ no no no no
runtimeStyle : Number
Reference to the Style object specifying the current runtime style(s) of the element.
No Details 5.0+ no no no no
scopeName : String
XML scope of the element.
No Details 5.0+ no no no no
scrollHeight : Number
Height (in pixels) of the total content area of the element.
No Details 4.0+ 1.0+ 7.0+ 7.0+ 1.0+
scrollLeft : Number
Number of pixels between the actual left edge of the element to the displayed left edge of the element.
No Details 4.0+ 1.0+ 7.0+ 7.0+ 1.0+
scrollTop : Number
Number of pixels between the actual top edge of the element to the displayed top edge of the element.
No Details 4.0+ 1.0+ 7.0+ 7.0+ 1.0+
scrollWidth : Number
Width (in pixels) of the total content area of the element.
No Details 4.0+ 1.0+ 7.0+ 7.0+ 1.0+
sourceIndex : Number
Index of the element in the Document.all[] array.
Show Details 4.0+ no no 8.0+ no

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/nodetree.html

style : HTMLStyleObject
Reference to the inline CSS style for the element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/style.html

Availability

HTML DOM Level 2

syncMaster : Boolean
If true, indicates that the time container of the element must synchronize playback with the element. Default is false.
No Details 5.5+ no no no no
tabIndex : Number
Indicates the tab order index for the element.
No Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
tagName : String
HTML tag name for the element.
Show Details 4.0+ 1.0+ 6.0+ 8.0+ 1.3+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/aboutnodes.html

Availability

HTML DOM Level 1

tagURN : String
URN for the XML Namespace of the element.
No Details 5.0+ no no no no
timeContainer : String
Gets or sets the type of timeline that corresponds to the element.
No Details 5.5+ no no no no
title : String
Value of the title attribute for the element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/innerhtml.html

Availability

HTML DOM Level 2|W3C

uniqueID : String
System-generated unique identifier for the element.
No Details 5.5+ no no no no

Inherited Functions

Method Action IE Mozilla Netscape Opera Safari
hasAttribute(String name) : Boolean
Determines if the given attribute exists on this element.
Show Details

Parameters

String name Name of the attribute to check.

Returns

Boolean

Using hasAttribute

if (!element.hasAttribute("id")) { element.setAttribute("id", "newvalue"); }

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes3.html

Remarks
Use this method to verify that an attribute exists on an Element before retrieving that attribute.
See Also

Attr.specified|Element.getAttribute|Element.setAttribute

Availability

HTML DOM Level 2HTML DOM Level 2|W3C

hasAttributeNS(String namespaceURI, String localName) : Boolean
Determines if the given attribute local name and namespace URI exists on this element
Show Details no 1.0+ 6.0+ 8.0+ 1.3+

Parameters

String namespaceURI Namespace URI of the attribute to check.
String localName Local name of the attribute to check.

Returns

Boolean

Using hasAttributeNS

/* Given the source XML: */ if (!element.hasAttributeNS("http://mozref.com/NS/test", "name")) { element.setAttributeNS("http://mozref.com/NS/test", "name", "newvalue"); }
Remarks
Similar to hasAttribute, this method returns a boolean value indicating an attribute exists on the given element. In this instance, the hasAttributeNS method takes an extra parameter specifying the namespace URI for the attribute, enabling you to check for attributes that have a namespace associated with them.
See Also

Element.getAttributeNS|Element.setAttributeNS

Availability

HTML DOM Level 2|W3C

removeAttribute(String name) : void
Removes an attribute by name
Show Details 4.0+ 1.0+ 6.0+ 8.0+ 1.0+

Parameters

String name Name of the attribute to remove.

Returns

void

Using removeAttribute

if (element.hasAttribute("id")) { element.removeAttribute("id"); }

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes2.html

Remarks
Removes the specified attribute from the element. If the attribute has a defined default value, it will be set to that default value.
Throws
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
See Also

Element.getAttribute|Element.setAttribute|Node.attributes

Availability

HTML DOM Level 2|W3C

Removes an attribute by local name and namespace URI
Show Details no 1.0+ 6.0+ 8.0+ no

Returns

void

Remarks
This method removes an attribute from an Element based on the attribute's local name and namespace URI. If this attribute has a default value, a new attribute with the default value will immediately replace it, with the same local name, namespace URI and namespace prefix as the original attribute.
Throws
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
See Also

Element.getAttributeNS|Element.removeAttribute|Element.setAttributeNS

Availability

HTML DOM Level 2|W3C

setAttribute(String name, String value) : void
Adds a new attribute.
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.0+
  • IE: IE removes event attributes when you try to set style attributes.

Parameters

String name Name of the attribute to set.
String value String value of the attribute to set.

Returns

void

Using setAttribute

var node = document.getElementById('address-list'); document.setAttribute('ref', 'urn:root'); document.setAttribute('datasources', 'http://mozref.com/reference/objects.rdf');

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes2.html

Remarks
Sets either a new attribute value or updates an existing attribute value. This method can only set values as text strings, not HTML. Entities will not be parsed. To assign values containing entities to an attribute, use setAttributeNode or setAttributeNodeNS.
Throws
Raises an INVALID_CHARACTER_ERR error if the supplied name contains an invalid character.
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
See Also

Element.getAttribute|Element.removeAttribute|Element.setAttributeNode

Availability

HTML DOM Level 2|W3C

setAttributeNS(String namespaceURI, String qualifiedName, String value) : void
Adds a new attribute with a namespace URI
Show Details no 1.0+ 6.0+ 8.0+ no

Parameters

String namespaceURI Namespace URI of the attribute to set.
String qualifiedName Fully qualified name of the attribute to set.
String value String value of the attribute to set.

Returns

void

Using setAttributeNS

node.setAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:about", "urn:root" );
Remarks

This method, similar to the setAttribute method, sets a new attribute value. If the attribute already exists, it's value is set to the one supplied to this method. This version of the method however takes both a qualified name and namespace URI when setting the attribute. This permits the creation of attributes defined with namespaces.

Like setAttribute, this method accepts only plain string values, and as such cannot be used for defining entity references within strings. Any entity reference will be escaped prior to being set with the attribute. If you would like to assign values containing entities to an attribute, please see setAttributeNode or setAttributeNodeNS.

Throws
Raises an INVALID_CHARACTER_ERR error if the supplied name contains an invalid character.
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
Raises a NAMESPACE_ERR error if the qualifiedName is invalid, if the qualifiedName contains a namespace prefix yet no namespaceURI is supplied, if the namespace prefix is "xml" or "xmlns" and has a namespaceURI that does not match the prefix.
See Also

Element.setAttribute|Element.setAttributeNode

Availability

HTML DOM Level 2|W3C

Functions

Method Action IE Mozilla Netscape Opera Safari
addBehavior(String url) : HTMLElement
Attaches a behavior to the element as specified in url.
Show Details 5.0+ no no no no

Parameters

String url Reference to the behavior to attach.

Returns

HTMLElement

addEventListener(String whichEvent, Object handler, Boolean direction) : HTMLElement
Attaches an event listener to an HTMLElement that executes a function when the specified event occurs.
Show Details no 1.0+ no 7.0+ 1.0+

Parameters

String whichEvent Event to trigger the specified function.
Object handler Function to execute when the specified event occurs.
Boolean direction Specify true to fire the event during the capture phase. Specify false to fire the event during the bubbling phase.

Returns

HTMLElement

For examples, see the quirksmode test page:

http://www.quirksmode.org/js/events/registration.html

Availability

HTML DOM Level 2

appendChild(Node newChild) : HTMLElement
Appends a child element to the end of the childNodes[] array for the element.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • IE: Appending an "option" element to a "select" element may crash IE 5.0 on Windows.

Parameters

Node newChild Node to add to the current element as a child.

Returns

HTMLElement

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

Availability

HTML DOM Level 1

applyElement(String newElement, [String where]) : HTMLElement
Adds a new element to the current element either as a child or parent of the current element.
Show Details 5.5+ no no no no

Parameters

String newElement Tag name of the element to add.
String where (optional)Specifies where to add the new element (i.e. either as a parent or child of the current element). Specify a value of "outside" (or omit) to add the new element as a parent to the current element. Otherwise the new element becomes the first child of the current element and any existing children of the current element then become direct children of the new element.

Returns

HTMLElement

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

attachEvent(String whichHandler, String theFunction) : void
Attaches the specified event handler and function to the element so that every time the event fires, the function is called.
Show Details 5.0+ no no 8.0+ no

Parameters

String whichHandler Event handler to attach.
String theFunction Function to attach to the event handler.

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/js/events/registration.html

blur() : void
Removes focus from the element.
Show Details 5.0+ 1.0+ 3.0+ 7.0+ 1.0+

Returns

void

Availability

HTML DOM Level 1

Removes all attributes and values from the element.
Show Details 5.0+ no no no no

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes3.html

click() : void
Simulates a mouse click on the element. Fires the onclick event.
Show Details 4.0+ 1.0+ 2.0+ 7.0+ 1.0+

Returns

void

cloneNode(Boolean cloneChildren) : Node
Clones a node and returns the new node.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • IE: On a Mac, IE 5.0 does not clone the event handlers for an element.

Parameters

Boolean cloneChildren If true, specifies that any child nodes of the node should also be cloned.

Returns

Node

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

Availability

HTML DOM Level 1

componentFromPoint(Boolean x, Boolean y) : String
Returns a string describing the component at the specified location.
Show Details 5.0+ no no no no

Parameters

Boolean x X-coordinate (in pixels).
Boolean y Y-coordinate (in pixels).

Returns

String

contains(Boolean element) : Boolean
Returns true if the HTMLElement contains the specified element.
Show Details 5.0+ no no 8.0+ no

Parameters

Boolean element Element to check for.

Returns

Boolean

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/basics.html

detachEvent(Object whichHandler, Object theFunction) : void
Detaches the specified function from the event handler so that the function is no longer called when the event fires.
Show Details 5.0+ no no 8.0+ no

Parameters

Object whichHandler Event handler to detach.
Object theFunction Function to detach.

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/js/events/registration.html

dispatchEvent(Boolean event) : void
Redirects the specified event instance to be processed by the appropriate handler.
Show Details no 1.0+ 6.0+ 7.0+ 1.0+

Parameters

Boolean event Event to redirect.

Returns

void

Availability

HTML DOM Level 2

dragDrop() : void
Fires a drag event on the element.
Show Details 5.5+ no no no no

Returns

void

fireEvent(Boolean handler, [Boolean event]) : void
Fires an instance of the specified event.
Show Details 5.5+ no no no no

Parameters

Boolean handler Event handler for the event.
Boolean event (optional)Event to fire.

Returns

void

focus() : void
Gives focus to the element.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

Returns

void

Availability

HTML DOM Level 2

getAdjacentText(String where) : String
Gets the string of text in the position specified by where.
Show Details 5.0+ no no no no

Parameters

String where Specifies where to get the adjacent text from, relative to the element. Valid values are beforeBegin, afterBegin, beforeEnd, and afterEnd.

Returns

String

getAttribute(String attributeName) : String
Gets the value of the specified attribute.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

Parameters

String attributeName Name of the attribute.

Returns

String

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes2.html

getAttributeNode(String attributeName) : Node
Gets the node of the specified attribute.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+

Parameters

String attributeName Name of the attribute.

Returns

Node

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes2.html

Availability

HTML DOM Level 1

Returns a TextRectangle that marks the top, bottom, left, and right boundaries (in pixels) of the content of the element.
Show Details 5.0+ 1.9+ no no no

Returns

Object

getClientRects() : Object
Returns a collection of all of the TextRectangle objects contained by the element.
Show Details 5.0+ 1.9+ no no no

Returns

Object

static getElementsByTagName(String tagname) : Array
Returns an array of Element nodes with the specified tag name.
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.0+
  • IE: Does not work in IE 5.0 on Windows.

Parameters

String tagname (one-or-more)Tag name of the elements to return. Specify "*" to return all tags.

Returns

Array

Using getElementsByTagName

// Assume there is only one 

For additional examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/basics.html

Remarks

This method returns a list of elements in the document that have the specified tagName. The returned NodeList is sorted in the order the elements were found during a depth-first preorder traversal through the node tree.

See Also

Document.getElementById|Element.getElementsByTagName|HTMLDocument.getElementsByName

Availability

HTML DOM Level 1

getExpression(String propertyName) : String
Returns the property expression specified by propertyName.
Show Details 5.0+ no no no no

Parameters

String propertyName Name of the property/attribute.

Returns

String

hasAttribute(String name) : Boolean
Determines if the given attribute exists on this element.
Show Details no 1.0+ 6.0+ 7.0+ 1.3+

Parameters

String name Name of the attribute to check.

Returns

Boolean

Using hasAttribute

if (!element.hasAttribute("id")) { element.setAttribute("id", "newvalue"); }

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes3.html

Remarks
Use this method to verify that an attribute exists on an Element before retrieving that attribute.
See Also

Attr.specified|HTMLElement.getAttribute|HTMLElement.setAttribute

Availability

HTML DOM Level 2

hasAttributes() : Boolean
Returns true if the node is an element node with attributes.
Show Details no 1.0+ 6.0+ 7.0+ 1.3+

Returns

Boolean

Using hasAttributes

var obj = document.Document.getElementById('EmailAddress'); if (obj.hasAttributes()) { window.alert("The node " + obj.Node.nodeName + " has attributes"); }

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes3.html

Remarks
Returns true if this node is an Element and has any attributes. Returns false if there are none. Equivilant to checking node.attributes.NamedNodeMap.length > 0.
See Also

HTMLElement.getAttribute|HTMLElement.hasAttribute|Node.attributes

Availability

HTML DOM Level 2

hasChildNodes() : Boolean
Returns true if the node has child nodes.
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.0+

Returns

Boolean

Using hasChildNodes

var obj = document.Document.getElementById('EmailAddress'); if (obj.hasChildNodes()) { window.alert("The node " + obj.Node.nodeName + " has children"); }
Remarks
Returns true if this node has any child nodes. Returns false if there are none. Equivilant to checking node.childNodes.NodeList.length > 0.
See Also

Node.childNodes

Availability

HTML DOM Level 1

insertAdjacentElement(String where, Element element) : void
Inserts the specified Element object adjacent to this element.
Show Details 5.0+ no no no no

Parameters

String where Specifies where to insert the element. Valid values are beforeBegin, afterBegin, beforeEnd, and afterEnd.
Element element Element to insert.

Returns

void

See Also

HTMLElement.insertAdjacentHTML|HTMLElement.insertText

insertAdjacentHTML(String where, String text) : void
Inserts the specified string of HTML text adjacent to this element. Parsed as HTML.
Show Details 4.0+ no no no no

Parameters

String where Specifies where to insert the element. Valid values are beforeBegin, afterBegin, beforeEnd, and afterEnd.
String text HTML text to insert.

Returns

void

See Also

HTMLElement.insertAdjacentElement|HTMLElement.insertAdjacentText

insertAdjacentText(String where, String text) : void
Inserts the specified string of HTML text adjacent to this element. Not parsed as HTML.
Show Details 4.0+ no no no no

Parameters

String where Specifies where to insert the element. Valid values are beforeBegin, afterBegin, beforeEnd, and afterEnd.
String text Text string to insert.

Returns

void

See Also

HTMLElement.insertAdjacentElement|HTMLElement.insertAdjacentHTML|HTMLElement.replaceAdjacentText

insertBefore(Node newChild, Node refChild) : void
Inserts a new child node in front of the reference child node.
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.0+

Parameters

Node newChild New child node to insert.
Node refChild Reference child node.

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

See Also

HTMLElement.replaceNode

Availability

HTML DOM Level 1

isSupported(String feature, [String version]) : Boolean
Returns true if the specified feature and version are supported.
Show Details no 1.0+ 6.0+ 8.0+ 1.0+

Parameters

String feature Name of the feature.
String version (optional)Version of the feature.

Returns

Boolean

Remarks
Tests whether a node supports the specified feature. Similar to the DOMImplementation.hasFeature method and takes the same feature names. If version is null, returns true if any version of the feature is supported.
See Also

DOMImplementation.hasFeature

Availability

HTML DOM Level 2

mergeAttributes(Object source, [Boolean preserve]) : void
Merges the attributes from the source element to the current element.
Show Details 5.0+ no no no no

Parameters

Object source Source that supplies the attributes.
Boolean preserve (optional)If true, specifies that the id of the current element should be preserved.

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes.html

normalize() : void
Merges text nodes adjacent to the element to create a normalized DOM.
Show Details N/A 1.0+ 6.0+ 8.0+ no
  • IE: May crash IE 6.0.

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/splittext.html

Remarks
Normalizes any Text nodes contained under this node and all of its children. Merges any adjacent Text nodes into one object, so that the nodes reflect how they would be structured if this XML document were freshly loaded.

Normalize() is useful for manipulating the text content of nodes for editing. Instead of worrying about altering existing Text nodes, you can simply add new nodes and perform the normalize when you finish your updates.

Availability

HTML DOM Level 1

Stops the mouse from capturing events on the element.
Show Details 5.0+ no no no no

Returns

void

removeAttribute(String name) : void
Removes an attribute by name
Show Details 6.0+ 1.0+ 6.0+ 8.0+ 1.0+
  • IE: IE does not remove events.

Parameters

String name Name of the attribute to remove.

Returns

void

Using removeAttribute

if (element.hasAttribute("id")) { element.removeAttribute("id"); }

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes2.html

Remarks
Removes the specified attribute from the element. If the attribute has a defined default value, it will be set to that default value.
Throws
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
See Also

HTMLElement.getAttribute|HTMLElement.setAttribute|Node.attributes

Availability

HTML DOM Level 1

static removeAttributeNode(Attr oldAttr) : Attr
Removes the specified attribute node
Show Details 6.0+ 1.0+ 6.0+ 8.0+ 1.0+
  • IE: Minimal support in IE 6.0 (Windows) and IE 5 (Mac).

Parameters

Attr oldAttr Node to remove from the attribute.

Returns

Attr

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes2.html

Remarks
Removes an attribute from an element. If the attribute has a defined default value, the new attribute node value will immediately be set to that.
Throws
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only. Raises a NOT_FOUND_ERR error if oldAttr object is not an attribute of this element.
See Also

Attr|Element.removeAttribute

Availability

HTML DOM Level 1

static removeBehavior(String id) : Boolean
Removes the specified attribute node
Show Details 5.0+ no no no no

Parameters

String id id of the behavior to remove.

Returns

Boolean

Remarks
Removes the behavior specified by id from the element.
See Also

HTMLElement.addBehavior

static removeChild(Node oldChild) : Node
Removes the specified child node from the element and returns the node.
Show Details 5.0+ 1.0+ 6.0+ 8.0+ 1.0+

Parameters

Node oldChild Child node to remove.

Returns

Node

Using removeChild

var obj = document.Document.getElementById('EmailAddress'); try { var oldChild = obj.removeChild(obj.Node.firstChild); } catch DOMException { // Error handling };

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

Remarks
Removes and returns the specified child node from the list of this node's children.
Throws
Raises a NO_MODIFICATION_ALLOWED_ERR if the node is read-only.
Raises a NOT_FOUND_ERR if the supplied node is not a child of this one.
See Also

Node.appendChild|Node.insertBefore|Node.replaceChild

Availability

HTML DOM Level 1

removeEventListener(String type, EventListener listener, Boolean useCapture) : void
Removes an event listener from an event target.
Show Details no 1.0+ no 7.0+ 1.0+

Parameters

String type Type of event.
EventListener listener Event listener to be removed.
Boolean useCapture Specify "true" to remove a capturing event listener. Specify "false" to remove all other types of event listeners.

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/js/events/registration.html

Availability

HTML DOM Level 2

removeExpression(String propertyName) : void
Removes the specified property expression from the element.
Show Details 5.0+ no no no no

Parameters

String propertyName Name of the property expression to remove.

Returns

void

replaceAdjacentText(String where, String text) : void
Replaces the current text adjacent to the element with the specified text.
Show Details 5.0+ no no no no

Parameters

String where Specifies where to insert the element. Valid values are beforeBegin, afterBegin, beforeEnd, and afterEnd.
String text Text to replace the current text with.

Returns

void

See Also

HTMLElement.insertAdjacentText

static replaceChild(Node newChild, Node oldChild) : Node
Removes the specified child node, replaces it with another node, and returns the removed node.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

Parameters

Node newChild Node to replace the oldChild node with.
Node oldChild Node to be replaced.

Returns

Node

Using replaceChild

var obj = document.Document.getElementById('EmailAddress'); var newElement = document.Document.createElement('label'); try { var oldChild = obj.replaceChild(newElement, obj.Node.lastChild); } catch DOMException { // Error handling };

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

Remarks
This method simplifies the process of calling removeChild and then insertBefore, so that you do not have to worry if this node is the first or last child.

The new child node is removed if it already exists somewhere else in the DOM tree. If the new child is a DocumentFragment node, the oldChild node is replaced by all of the nodes within the DocumentFragment, in the same order.

Throws
Raises a HIERARCHY_REQUEST_ERR error if either the node being inserted is one of this node's ancestors, or if the current node does not allow this type of node as a child.
Raises a WRONG_DOCUMENT_ERR error if the newChild node was not created within the current document.
Raises a NO_MODIFICATION_ALLOWED_ERR if this node is read-only or if the parent of the new node is read-only.
Raises a NOT_FOUND_ERR if the supplied oldChild node is not a child of this one.
See Also

HTMLElement.appendChild|HTMLElement.insertBefore|HTMLElement.removeChild

Availability

HTML DOM Level 1

replaceNode(Node newNode) : void
Replaces the current node with the node specified in newNode.
Show Details 5.0+ no no no no

Parameters

Node newNode Node to replace the current node with.

Returns

void

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

See Also

HTMLElement.insertBefore

scrollIntoView([Boolean alignToTop]) : void
Immediately scrolls the element into the viewable portion of the web page.
Show Details 4.0+ 1.0+ 7.0+ no no

Parameters

Boolean alignToTop (optional)If true, specifies that the top of the element will be scrolled to align with the top of the window. Default is true.

Returns

void

Remarks
Use the scrollIntoView method to visually direct users to a specific part of a web page, without forcing the users to scroll the page themselves. (e.g. Scrolling down to the "total" of a long shopping cart page.)
setActive() : void
Sets this element as "active" without giving focus to the element.
Show Details 5.5+ no no no no

Returns

void

setAttribute(String name, String value) : void
Adds a new attribute.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • IE: IE removes event attributes when you try to set style attributes.

Parameters

String name Name of the attribute to set.
String value String value of the attribute to set.

Returns

void

Using setAttribute

var node = document.getElementById('address-list'); document.setAttribute('ref', 'urn:root'); document.setAttribute('datasources', 'http://mozref.com/reference/objects.rdf');

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes2.html

Remarks
Sets either a new attribute value or updates an existing attribute value. This method can only set values as text strings, not HTML. Entities will not be parsed. To assign values containing entities to an attribute, use setAttributeNode.
Throws
Raises an INVALID_CHARACTER_ERR error if the supplied name contains an invalid character.
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
See Also

HTMLElement.getAttribute|HTMLElement.removeAttribute|HTMLElement.setAttributeNode

Availability

HTML DOM Level 1

static setAttributeNode(Attr newAttr) : Attr
Adds the given attribute node
Show Details 6.0+ 1.0+ 6.0+ 8.0+ 1.0+
  • Safari: Safari will create the attribute, but you will have to use nodeValue to set its value.

Parameters

Attr newAttr Attr node of the attribute to set.

Returns

Attr

Using setAttributeNode

var attr = node1.getAttributeNode("class"); node1.removeAttribute("class"); node2.setAttributeNode(attr);

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes3.html

Remarks

This method adds the specified Attr object as an attribute to the current element. You may specifiy actual DOM nodes instead of specifying separate arguments for the attribute name and value.

If the element already has the attribute, setAttribute will replace the node and return the old attribute node. Returns null, otherwise.

Throws
Raises a WRONG_DOCUMENT_ERR error if the supplied newAttr was created from a different document.
Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
Raises an INUSE_ATTRIBUTE_ERR error if the supplied newAttr is already bound to another Element object.
See Also

Attr|HTMLElement.setAttribute

Availability

HTML DOM Level 1

setCapture([Boolean containerCapture]) : void
Sets mouse capture to the element.
Show Details 5.0+ no no no no

Parameters

Boolean containerCapture (optional)If true, specifies that events that originate in the container will be captured by the container.

Returns

void

Remarks
Once set, routes all mouse events to this element.
setExpression(String property, String expression, [String language]) : void
Sets the specified expression on the specified property of an element.
Show Details 5.0+ no no no no

Parameters

String property Name of the property to add the expression to.
String expression Expression to set.
String language (optional)Scripting language to use. Default is JScript. Other valid values are JavaScript and VBScript.

Returns

void

See Also

HTMLElement.removeExpression

swapNode(Node node) : Node
Swaps the current node with the specified node in the document.
Show Details 5.0+ no no no no

Parameters

Node node Node to swap this node with.

Returns

Node

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/movingnodes.html

unwatch(String property) : void
Removes the watchpoint from the specified property.
Show Details no no 4.0+ no no

Parameters

String property Property to remove the watch point from.

Returns

void

watch(String property, String handler) : void
Sets a watch point on a property. When the value of that property changes, the specified handler is automatically invoked.
Show Details no no 4.0+ no no

Parameters

String property Property to set the watch point on.
String handler Handler to invoke when the specified property changes.

Returns

void

References

HTMLAnchorElement|HTMLBodyElement|HTMLDocument|HTMLFormElement|HTMLInputElement|HTMLOptionElement|HTMLSelectElement|HTMLTableCaptionElement|HTMLTableCellElement|HTMLTableColElement|HTMLTableElement|HTMLTableRowElement|HTMLTableSectionElement|HTMLTextAreaElement

Availability

HTML DOM Level 2|W3C

text_javascript aptana_docs
in the document var body = document.getElementsByTagName("body").item(0); var paragraphs = body.getElementsByTagName("p");