English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
The following table lists the properties of the Element object:
Properties | Description |
---|---|
accessKey | Sets or returns the element's accesskey attribute |
attributes | Returns the NamedNodeMap of the element's attributes |
childElementCount | Returns the number of child elements of the given element |
childNodes | Returns a list of the element's child nodes (including text and comment nodes) |
children | Returns a list of the element's child elements (excluding text and comment nodes) |
classList | Returns the class name of the element |
className | Sets or returns the value of the element's class attribute |
clientHeight | Returns the height of the element, including padding |
clientLeft | Returns the width of the left border of the element |
clientTop | Returns the width of the top border of the element |
clientWidth | Returns the width of the element, including padding |
contentEditable | Sets or returns whether the content of the element is editable |
dir | Sets or returns the value of the element's dir attribute |
firstChild | Returns the first child node |
firstElementChild | Returns the first child element (excluding text and comment nodes) |
id | Sets or returns the value of the element's id attribute |
innerHTML | Sets or returns the content of the element |
innerText | Sets or returns the text content of the element and its descendants |
isContentEditable | Returns true if the content of the element is editable; otherwise, returns false |
lang | Sets or returns the value of the element's lang attribute |
lastChild | Returns the last child node of the element |
lastElementChild | Returns the last child element of the element (excluding text and comment nodes) |
namespaceURI | Returns the namespace URI of the element |
nextSibling | Returns the next node at the same tree level of the same node |
nextElementSibling | Returns the next element at the same tree level of the same node (excluding text and comment nodes) |
nodeName | Returns the name of the node |
nodeType | Returns the node type of the node |
nodeValue | Sets or returns the value of the node |
offsetHeight | Returns the height of the element, including padding, border, and scrollbars |
offsetWidth | Returns the width of the element, including padding, border, and scrollbars |
offsetLeft | Returns the horizontal offset position of the element |
offsetParent | Returns the offset container of the element |
offsetTop | Returns the vertical offset position of the element |
ownerDocument | Returns the root element (document object) of the element |
parentNode | Returns the parent node of the element |
parentElement | Returns the parent element of the element |
previousSibling | Returns the previous node at the same tree level of the same node |
previousElementSibling | Returns the previous element at the same tree level of the same node (excluding text and comment nodes) |
scrollHeight | Returns a Number representing the scroll view height of the element |
scrollLeft | Sets or returns the pixel value of the horizontal scrolling of the element's content |
scrollTop | Sets or returns the pixel value of the vertical scrolling of the element's content |
scrollWidth | Returns a Number representing the scroll view width of the element |
style | Sets or returns the value of the element's style attribute |
tabIndex | Sets or returns the value of the element's tabindex attribute |
tagName | Returns the tag name of the element |
textContent | Sets or returns the text content of the node and its descendants |
title | Sets or returns the value of the element's title attribute |
The table below lists the methods of the Element object:
Method | Description |
---|---|
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 |