HTML DOM element object
HTML DOM Nodes
In the HTML DOM (Document Object Model), everything is a **node**:
- The document itself is a document object
- All HTML elements are element nodes
- All HTML attributes are attribute nodes
- The text inserted into an HTML element is a text node
- A comment is a comment node
Element object
In the HTML DOM, Element objectrepresents an HTML element.
An element object's Child nodechildren can be element nodes, text nodes, or comment nodes.
NodeList object Represents a list of nodes, similar to a collection of child nodes of HTML elements.
Elements can have attributes. Attributes belong to attribute nodes (see the next section).
Browser support





All major browsers support the element object and the NodeList object.
Properties and methods
The above properties and methods apply to all HTML elements:
| Attribute / Method | Description |
|---|---|
| element.accessKey | Sets or returns the accesskey of an element |
| element.addEventListener() | Adds an event handler to a specified element |
| element.appendChild() | Adds a new child element to an element |
| element.attributes | Returns an array of attributes of an element |
| element.childNodes | Returns an array of child nodes of an element |
| element.children | Returns a collection of child elements of an element |
| element.classList | Returns the class name of an element, as a DOMTokenList object. |
| element.className | Sets or returns the class attribute of an element |
| element.clientTop | Represents the width of the top border of an element, in pixels. |
| element.clientLeft | Represents the width of the left border of an element, in pixels. |
| element.clientHeight | Returns the visible height of the content on the page (height includes padding but excludes border, margin, and scrollbar) |
| element.clientWidth | Returns the visible width of the content on the page (width includes padding but excludes border, margin, and scrollbar) |
| element.cloneNode() | Clones an element |
| element.compareDocumentPosition() | Compares the document position of two elements. |
| element.contentEditable | Sets or returns whether the content of an element is editable |
| element.dir | Sets or returns the text direction in an element |
| element.firstElementChild | Returns the first child element of an element |
| element.firstChild | Returns the first child node of an element |
| element.focus() | Sets the document or element to get focus |
| element.getAttribute() | Returns the attribute value of a specified element |
| element.getAttributeNode() | Returns the specified attribute node |
| element.getElementsByTagName() | Returns a collection of all child elements with the specified tag name. |
| element. getElementsByClassName() | Returns a collection of all elements with the specified class name in the document, as a NodeList object. |
| element.getFeature() | Returns the object for executing specified features (APIs). |
| element.getUserData() | Returns an object of associated key values in an element. |
| element.hasAttribute() | Returns true if the specified attribute exists in the element, otherwise returns false. |
| element.hasAttributes() | Returns true if the element has any attributes, otherwise returns false. |
| element.hasChildNodes() | Returns whether an element has any child elements |
| element.hasFocus() | Returns a boolean indicating whether the document or element has focus |
| element.id | Sets or returns the id of an element. |
| element.innerHTML | Sets or returns the content of an element. |
| element.insertBefore() | Inserts a new child element before an existing child element |
| element.isContentEditable | Returns true if the element content is editable, otherwise returns false |
| element.isDefaultNamespace() | Returns true if a namespaceURI is specified, otherwise returns false. |
| element.isEqualNode() | Checks whether two elements are equal |
| element.isSameNode() | Checks whether two elements have all the same nodes. |
| element.isSupported() | Returns true if the specified feature is supported in the element. |
| element.lang | Sets or returns the language of an element. |
| element.lastChild | Returns the last child node |
| element.lastElementChild | Returns the last child element of the specified element |
| element.matches() | If the element matches the specified CSS selector, the matches() method returns true, otherwise returns false. |
| element.namespaceURI | Returns the namespace URI. |
| element.nextSibling | Returns the node immediately following this element |
| element.nextElementSibling | Returns the next sibling element after the specified element (the next element node in the same node tree level). |
| element.nodeName | Returns the tag name of an element (uppercase) |
| element.nodeType | Returns the node type of an element |
| element.nodeValue | Returns the node value of an element |
| element.normalize() | Makes this a "normal" form in which only structures (such as elements, comments, processing instructions, CDATA sections, and entity references) separate Text nodes, that is, all text nodes under an element (including attributes) have neither adjacent text nodes nor empty text nodes |
| element.offsetHeight | Returns the height of any element including the border and padding, but excluding the margin |
| element.offsetWidth | Returns the width of an element including the border and padding, but excluding the margin |
| element.offsetLeft | Returns the offset container of the current element's relative horizontal offset position |
| element.offsetParent | Returns the offset container of an element |
| element.offsetTop | Returns the offset container of the current element's relative vertical offset position |
| element.ownerDocument | Returns the root element of an element (document object) |
| element.parentNode | Returns the parent node of an element |
| element.previousSibling | Returns the element immediately preceding a given element |
| element.previousElementSibling | Returns the previous sibling element of the specified element (the previous element node in the same node tree level). |
| element.querySelector() | Returns the first child element that matches the specified CSS selector |
| document.querySelectorAll() | Returns a list of all child element nodes that match the specified CSS selector |
| element.removeAttribute() | Removes the specified attribute from an element |
| element.removeAttributeNode() | Removes the specified attribute node and returns the removed node. |
| element.removeChild() | Removes a child element |
| element.removeEventListener() | Removes the event handler added by the addEventListener() method |
| element.replaceChild() | Replaces a child element |
| element.scrollHeight | Returns the full height of an element (including the hidden parts with scrollbars) |
| element.scrollLeft | Returns the distance between the left edge of the actual element and the left edge in the current view |
| element.scrollTop | Returns the distance between the top edge of the actual element and the top edge in the current view |
| element.scrollWidth | Returns the full width of an element (including the hidden parts with scrollbars) |
| element.setAttribute() | Sets or changes the specified attribute and its value. |
| element.setAttributeNode() | Sets or changes the specified attribute node. |
| element.setIdAttribute() | |
| element.setIdAttributeNode() | |
| element.setUserData() | Associates an object with a specified key value in an element. |
| element.style | Sets or returns the style attribute of an element |
| element.tabIndex | Sets or returns the tab order of an element. |
| element.tagName | Returns the tag name (uppercase) of an element as a string |
| element.textContent | Sets or returns a node and its text content |
| element.title | Sets or returns the title attribute of an element |
| element.toString() | Converts an element to a string |
| nodelist.item() | Returns the index of an element based on the document tree |
| nodelist.length | Returns the number of nodes in the node list. |