XML DOM HTMLElement Object
- Previous Page DOM HTMLDocument
- Next Page DOM NamedNodeMap
The HTMLElement object represents an element in HTML.
Properties of HTMLElement object
Each element in an HTML document has an attribute corresponding to the HTML attribute of the element. Here are all the attributes supported by all HTML tags. Other attributes are specific to a certain type of HTML tag. The HTMLElement object inherits Node and Element Standard properties of the object, and also implements several non-standard properties described below:
- className
-
It specifies the class attribute of the element. Note: The attribute name is not "class" because "class" is a reserved word in JavaScript.
Type: String. Status: writable.
- currentStyle
-
This specific IE attribute applies to the cascade group of all CSS properties of the element. It is an alternative to Window.getComputedStyle() for IE only.
Type: String. Status: writable.
- dir
-
It specifies the dir attribute of the element, which declares the direction of the document text.
Type: String. Status: writable.
- id
-
It specifies the id attribute of the element. In a document, no two elements have the same id value.
Type: String. Status: writable.
- innerHTML
-
It specifies the string contained by the element, excluding the element's start and end tags. Querying this attribute will return the content of the element as an HTML text string. Setting this attribute to an HTML text string can replace the content of the element with HTML parsing syntax. This attribute cannot be set when the document is loaded. This is a non-standard attribute derived from IE4, which has been supported by all modern browsers.
Type: String. Status: writable.
- lang
-
The lang attribute of the element declares the language code of the element's content.
Type: String. Status: writable.
- offsetHeight, offsetWidth
-
返回元素的高度和宽度,以像素为单位。这是非标准的但却得到很好支持的属性。
scrollHeight, scrollWidth
- offsetHeight, offsetWidth
-
Returns the height and width of the element in pixels. This is a non-standard but well-supported attribute.
scrollHeight, scrollWidth
- offsetLeft
-
Returns the offset, in pixels, from the left boundary of the current element to the left boundary of its containing element.
scrollHeight, scrollWidth
- offsetTop
-
Returns the offset, in pixels, from the top boundary of the current element to the top boundary of its containing element.
Type:Node. Status: read-only.
- offsetParent
-
Returns a reference to the nearest dynamically positioned containing element, with all offsets determined by that element. If the element's style.display is set to none, this property returns null. This is a non-standard but well-supported attribute.
scrollHeight, scrollWidth
- Type: int. Status: read-only. Returns the complete height and width of the element in pixels. When an element has a scrollbar (such as due to the CSS overflow property), these properties are different from offsetHeight and offsetWidth, as offsetHeight and offsetWidth only report the size of the visible part of the element. This is a non-standard but well-supported attribute.
-
scrollTop, scrollLeft
Type: int. Status: writable. Sets or returns the number of pixels scrolled to the left or top edge of the element. These pixels are useful only when the element has a scrollbar, for example, when the element's CSS overflow property is set to auto. These properties are also only defined on the <body> or <html> tags in the document (this depends on the browser), and together they determine the position of the scrolling document. Note that these properties do not specify the scrolling amount of an <iframe> tag. This is a non-standard but well-supported attribute.
- style
-
Returns the value of the style attribute set for the inline CSS of the current element. Note that the value of this attribute is not a string.
Type:CSS2Properties. Status: read-only.
- title
-
Specifies the element's title attribute. When the mouse hovers over the element, many browsers display the value of this attribute in the element's 'tool tip'.
Type: String. Status: writable.
methods of HTMLElement object
The HTMLElement object inherits Node and Element object's standard methods. Certain types of elements implement methods specific to the marker, CodeW3C.com at HTML DOM Reference ManualEach marker's reference page provides information about these methods.
Most modern browsers also implement the following non-standard methods:
Method | Description |
---|---|
scrollIntoView() | Scroll the document. Make the element appear at the top or bottom of the window. |
HTMLElement object event handlers
All HTML elements that respond to mouse and keyboard events can trigger the event handlers listed here. Certain elements, such as links and buttons, perform default operations when these events occur. For such elements, more details can be found inReference pages for specific elementsfor more information.
See HTML Event Attributes Reference Manual, to learn more about HTML event handlers.
How to get more detailed information about HTMLElement objects
In the HTML DOM reference manual of CodeW3C.com, we have created special reference pages for the DOM objects corresponding to HTML tags:
Related Pages
XML DOM Reference Manual:Document Object
XML DOM Reference Manual:Document.getElementById()
XML DOM Reference Manual:Document.getElementsByTagName()
- Previous Page DOM HTMLDocument
- Next Page DOM NamedNodeMap