The HTML DOM Element Object
The Element Object
In the HTML DOM, the Element object represents an HTML element, like P, DIV, A, TABLE, or any other HTML element.
Properties and Methods
The following properties and methods can be used on all HTML elements:
Property / Method | Description |
---|---|
accessKey | Sets or returns the accesskey attribute of an element |
addEventListener() | Attaches an event handler to the specified element |
appendChild() | Adds a new child node, to an element, as the last child node |
attributes | Returns a NamedNodeMap of an element's attributes |
blur() | Removes focus from an element |
childElementCount | Returns the number of child elements an element has |
childNodes | Returns a collection of an element's child nodes (including text and comment nodes) |
children | Returns a collection of an element's child element (excluding text and comment nodes) |
classList | Returns the class name(s) of an element |
className | Sets or returns the value of the class attribute of an element |
click() | Simulates a mouse-click on an element |
clientHeight | Returns the height of an element, including padding |
clientLeft | Returns the width of the left border of an element |
clientTop | Returns the width of the top border of an element |
clientWidth | Returns the width of an element, including padding |
cloneNode() | Clones an element |
closest() | Searches up the DOM tree for the closest element which matches a specified CSS selector |
compareDocumentPosition() | Compares the document position of two elements |
contains() | Returns true if a node is a descendant of a node, otherwise false |
contentEditable | Sets or returns whether the content of an element is editable or not |
dir | Sets or returns the value of the dir attribute of an element |
exitFullscreen() | Cancels an element in fullscreen mode |
firstChild | Returns the first child node of an element |
firstElementChild | Returns the first child element of an element |
focus() | Gives focus to an element |
getAttribute() | Returns the specified attribute value of an element node |
getAttributeNode() | Returns the specified attribute node |
getBoundingClientRect() | Returns the size of an element and its position relative to the viewport |
getElementsByClassName() | Returns a collection of all child elements with the specified class name |
getElementsByTagName() | Returns a collection of all child elements with the specified tag name |
hasAttribute() | Returns true if an element has the specified attribute, otherwise false |
hasAttributes() | Returns true if an element has any attributes, otherwise false |
hasChildNodes() | Returns true if an element has any child nodes, otherwise false |
id | Sets or returns the value of the id attribute of an element |
innerHTML | Sets or returns the content of an element |
innerText | Sets or returns the text content of a node and its descendants |
insertAdjacentElement() | Inserts a HTML element at the specified position relative to the current element |
insertAdjacentHTML() | Inserts a HTML formatted text at the specified position relative to the current element |
insertAdjacentText() | Inserts text into the specified position relative to the current element |
insertBefore() | Inserts a new child node before a specified, existing, child node |
isContentEditable | Returns true if the content of an element is editable, otherwise false |
isDefaultNamespace() | Returns true if a specified namespaceURI is the default, otherwise false |
isEqualNode() | Checks if two elements are equal |
isSameNode() | Checks if two elements are the same node |
isSupported() | Returns true if a specified feature is supported on the element |
lang | Sets or returns the value of the lang attribute of an element |
lastChild | Returns the last child node of an element |
lastElementChild | Returns the last child element of an element |
matches() | Returns a Boolean value indicating whether an element is matched by a specific CSS selector or not |
namespaceURI | Returns the namespace URI of an element |
nextSibling | Returns the next node at the same node tree level |
nextElementSibling | Returns the next element at the same node tree level |
nodeName | Returns the name of a node |
nodeType | Returns the node type of a node |
nodeValue | Sets or returns the value of a node |
normalize() | Joins adjacent text nodes and removes empty text nodes in an element |
offsetHeight | Returns the height of an element, including padding, border and scrollbar |
offsetWidth | Returns the width of an element, including padding, border and scrollbar |
offsetLeft | Returns the horizontal offset position of an element |
offsetParent | Returns the offset container of an element |
offsetTop | Returns the vertical offset position of an element |
outerHTML | Sets or returns the content of an element (including the start tag and the end tag) |
outerText | Sets or returns the outer text content of a node and its descendants |
ownerDocument | Returns the root element (document object) for an element |
parentNode | Returns the parent node of an element |
parentElement | Returns the parent element node of an element |
previousSibling | Returns the previous node at the same node tree level |
previousElementSibling | Returns the previous element at the same node tree level |
querySelector() | Returns the first child element that matches a specified CSS selector(s) of an element |
querySelectorAll() | Returns all child elements that matches a specified CSS selector(s) of an element |
remove() | Removes the element from the DOM |
removeAttribute() | Removes a specified attribute from an element |
removeAttributeNode() | Removes a specified attribute node, and returns the removed node |
removeChild() | Removes a child node from an element |
removeEventListener() | Removes an event handler that has been attached with the addEventListener() method |
replaceChild() | Replaces a child node in an element |
requestFullscreen() | Shows an element in fullscreen mode |
scrollHeight | Returns the entire height of an element, including padding |
scrollIntoView() | Scrolls the specified element into the visible area of the browser window |
scrollLeft | Sets or returns the number of pixels an element's content is scrolled horizontally |
scrollTop | Sets or returns the number of pixels an element's content is scrolled vertically |
scrollWidth | Returns the entire width of an element, including padding |
setAttribute() | Sets or changes the specified attribute, to the specified value |
setAttributeNode() | Sets or changes the specified attribute node |
style | Sets or returns the value of the style attribute of an element |
tabIndex | Sets or returns the value of the tabindex attribute of an element |
tagName | Returns the tag name of an element |
textContent | Sets or returns the textual content of a node and its descendants |
title | Sets or returns the value of the title attribute of an element |
toString() | Converts an element to a string |