Element

Оновлено: 09.03.2023

Об'єкт Element

У HTML DOM об’єкт Element представляє елемент HTML, наприклад P, DIV, A, TABLE або будь-який інший елемент HTML.

Властивості та методи

Наступні властивості та методи можна використовувати для всіх елементів HTML:

Property / MethodDescription
accessKeySets or returns the accesskey attribute of an element
addEventListener()Attaches an event handler to an element
appendChild()Adds (appends) a new child node to an element
attributesReturns a NamedNodeMap of an element's attributes
blur()Removes focus from an element
childElementCountReturns an elements's number of child elements
childNodesReturns a NodeList of an element's child nodes
childrenReturns an HTMLCollection of an element's child elements
classListReturns the class name(s) of an element
classNameSets or returns the value of the class attribute of an element
click()Simulates a mouse-click on an element
clientHeightReturns the height of an element, including padding
clientLeftReturns the width of the left border of an element
clientTopReturns the width of the top border of an element
clientWidthReturns the width of an element, including padding
cloneNode()Clones an element
closest()Searches the DOM tree for the closest element that matches a CSS selector
compareDocumentPosition()Compares the document position of two elements
contains()Returns true if a node is a descendant of a node
contentEditableSets or returns whether the content of an element is editable or not
dirSets or returns the value of the dir attribute of an element
firstChildReturns the first child node of an element
firstElementChildReturns the first child element of an element
focus()Gives focus to an element
getAttribute()Returns the value of an element's attribute
getAttributeNode()Returns an attribute node
getBoundingClientRect()Returns the size of an element and its position relative to the viewport
getElementsByClassName()Returns a collection of child elements with a given class name
getElementsByTagName()Returns a collection of child elements with a given tag name
hasAttribute()Returns true if an element has a given attribute
hasAttributes()Returns true if an element has any attributes
hasChildNodes()Returns true if an element has any child nodes
idSets or returns the value of the id attribute of an element
innerHTMLSets or returns the content of an element
innerTextSets or returns the text content of a node and its descendants
insertAdjacentElement()Inserts a new HTML element at a position relative to an element
insertAdjacentHTML()Inserts an HTML formatted text at a position relative to an element
insertAdjacentText()Inserts text into a position relative to an element
insertBefore()Inserts a new child node before an existing child node
isContentEditableReturns true if an element's content is editable
isDefaultNamespace()Returns true if a given namespaceURI is the default
isEqualNode()Checks if two elements are equal
isSameNode()Checks if two elements are the same node
isSupported()Deprecated
langSets or returns the value of the lang attribute of an element
lastChildReturns the last child node of an element
lastElementChildReturns the last child element of an element
matches()Returns true if an element is matched by a given CSS selector
namespaceURIReturns the namespace URI of an element
nextSiblingReturns the next node at the same node tree level
nextElementSiblingReturns the next element at the same node tree level
nodeNameReturns the name of a node
nodeTypeReturns the node type of a node
nodeValueSets or returns the value of a node
normalize()Joins adjacent text nodes and removes empty text nodes in an element
offsetHeightReturns the height of an element, including padding, border and scrollbar
offsetWidthReturns the width of an element, including padding, border and scrollbar
offsetLeftReturns the horizontal offset position of an element
offsetParentReturns the offset container of an element
offsetTopReturns the vertical offset position of an element
outerHTMLSets or returns the content of an element (including the start tag and the end tag)
outerTextSets or returns the outer text content of a node and its descendants
ownerDocumentReturns the root element (document object) for an element
parentNodeReturns the parent node of an element
parentElementReturns the parent element node of an element
previousSiblingReturns the previous node at the same node tree level
previousElementSiblingReturns the previous element at the same node tree level
querySelector()Returns the first child element that matches a CSS selector(s)
querySelectorAll()Returns all child elements that matches a CSS selector(s)
remove()Removes an element from the DOM
removeAttribute()Removes an attribute from an element
removeAttributeNode()Removes an 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
scrollHeightReturns the entire height of an element, including padding
scrollIntoView()Scrolls the an element into the visible area of the browser window
scrollLeftSets or returns the number of pixels an element's content is scrolled horizontally
scrollTopSets or returns the number of pixels an element's content is scrolled vertically
scrollWidthReturns the entire width of an element, including padding
setAttribute()Sets or changes an attribute's value
setAttributeNode()Sets or changes an attribute node
styleSets or returns the value of the style attribute of an element
tabIndexSets or returns the value of the tabindex attribute of an element
tagNameReturns the tag name of an element
textContentSets or returns the textual content of a node and its descendants
titleSets or returns the value of the title attribute of an element
toString()Converts an element to a string