English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM Element Object

Element element object

The Element object represents an HTML element, such as <p>, <div>, <a>, <form>, or any other HTML element.

The Element object only has methods and properties that are common to various elements.

Element object properties

The following table lists the properties of the Element object:

PropertiesDescription
accessKeySets or returns the element's accesskey attribute
attributesReturns the NamedNodeMap of the element's attributes
childElementCountReturns the number of child elements of the given element
childNodesReturns a list of the element's child nodes (including text and comment nodes)
childrenReturns a list of the element's child elements (excluding text and comment nodes)
classListReturns the class name of the element
classNameSets or returns the value of the element's class attribute
clientHeightReturns the height of the element, including padding
clientLeftReturns the width of the left border of the element
clientTopReturns the width of the top border of the element
clientWidthReturns the width of the element, including padding
contentEditableSets or returns whether the content of the element is editable
dirSets or returns the value of the element's dir attribute
firstChildReturns the first child node
firstElementChildReturns the first child element (excluding text and comment nodes)
idSets or returns the value of the element's id attribute
innerHTMLSets or returns the content of the element
innerTextSets or returns the text content of the element and its descendants
isContentEditableReturns true if the content of the element is editable; otherwise, returns false
langSets or returns the value of the element's lang attribute
lastChildReturns the last child node of the element
lastElementChildReturns the last child element of the element (excluding text and comment nodes)
namespaceURIReturns the namespace URI of the element
nextSiblingReturns the next node at the same tree level of the same node
nextElementSiblingReturns the next element at the same tree level of the same node (excluding text and comment nodes)
nodeNameReturns the name of the node
nodeTypeReturns the node type of the node
nodeValueSets or returns the value of the node
offsetHeightReturns the height of the element, including padding, border, and scrollbars
offsetWidthReturns the width of the element, including padding, border, and scrollbars
offsetLeftReturns the horizontal offset position of the element
offsetParentReturns the offset container of the element
offsetTopReturns the vertical offset position of the element
ownerDocumentReturns the root element (document object) of the element
parentNodeReturns the parent node of the element
parentElementReturns the parent element of the element
previousSiblingReturns the previous node at the same tree level of the same node
previousElementSiblingReturns the previous element at the same tree level of the same node (excluding text and comment nodes)
scrollHeightReturns a Number representing the scroll view height of the element
scrollLeftSets or returns the pixel value of the horizontal scrolling of the element's content
scrollTopSets or returns the pixel value of the vertical scrolling of the element's content
scrollWidthReturns a Number representing the scroll view width of the element
styleSets or returns the value of the element's style attribute
tabIndexSets or returns the value of the element's tabindex attribute
tagNameReturns the tag name of the element
textContentSets or returns the text content of the node and its descendants
titleSets or returns the value of the element's title attribute

Element object methods

The table below lists the methods of the Element object:

MethodDescription
addEventListener()Attaches an event handler to the specified element
appendChild()Adds a new child node to the element as the last child node
blur()Removes focus from the element
cloneNode()Clones the element
click()Simulates a mouse click on the element
compareDocumentPosition()Compares the document positions of two elements
contains()Returns true if the node is a descendant of the node; otherwise returns false
focus()Focuses on the element
getAttribute()Returns the specified attribute value of the element node
getAttributeNode()Returns the specified attribute node
getBoundingClientRect()Returns the size of the element and its position relative to the viewport
getElementsByClassName()Returns a list of all child elements with the specified class name
getElementsByTagName()Returns a list of all child elements with the specified tag name
hasAttribute()Returns true if the element has the specified attribute; otherwise returns false
hasAttributes()Returns true if the element has any attributes; otherwise returns false
hasChildNodes()Returns true if the element has any child nodes; otherwise returns false
insertAdjacentElement()Inserts an HTML element at the specified position relative to the current element
insertAdjacentHTML()Inserts HTML-formatted text at the specified position relative to the current element
insertAdjacentText()Inserts text at the specified position relative to the current element
insertBefore()Inserts a new child node before the specified existing child node
isDefaultNamespace()Returns true if the specified namespaceURI is the default value; otherwise returns false
isEqualNode()Checks if two elements are equal
isSameNode()Checks if two elements are at the same node
isSupported()Returns true if the element supports the specified feature
normalize()Connects adjacent text nodes and removes any empty text nodes from the element
querySelector()Returns the first child element that matches the specified CSS selector
querySelectorAll()Return all child elements that match the specified CSS selector of the element
removeAttribute()Remove the specified attribute from the element
removeAttributeNode()Remove the specified attribute node and return the removed node
removeChild()Remove a child node from the element
removeEventListener()Remove the event handler added to the addEventListener() method
replaceChild()Replace the child nodes in the element
requestFullscreen()Display the element in full-screen mode
scrollIntoView()Scroll the specified element into the visible area of the browser window
setAttribute()Set or change the specified attribute to the specified value
setAttributeNode()Set or change the specified attribute node
toString()Convert an element to a string