Element is the most general base class from which all objects in a Document inherit. It only has methods and properties common to all kinds of elements. More specific classes inherit from Element. For example, the HTMLElement interface is the base interface for HTML elements, while the SVGElement interface is the basis for all SVG elements. Most functionality is specified further down the class hierarchy.
Languages outside the realm of the Web platform, like XUL through the XULElement interface, also implement Element.
Inherits properties from its parent interface, Node, and by extension that interface's parent, EventTarget. It implements the properties of ParentNode, ChildNode, NonDocumentTypeChildNode, and Animatable.
Element.attributes Read only
NamedNodeMap object containing the assigned attributes of the corresponding HTML element.Element.classList Read only
DOMTokenList containing the list of class attributes.Element.classNameDOMString representing the class of the element.Element.clientHeight Read only
Number representing the inner height of the element.Element.clientLeft Read only
Number representing the width of the left border of the element.Element.clientTop Read only
Number representing the width of the top border of the element.Element.clientWidth Read only
Number representing the inner width of the element.Element.computedName Read only
DOMString containing the label exposed to accessibility.Element.computedRole Read only
DOMString containing the ARIA role that has been applied to a particular element. Element.idDOMString representing the id of the element.Element.innerHTMLDOMString representing the markup of the element's content.Element.localName Read only
DOMString representing the local part of the qualified name of the element.Element.namespaceURI Read only
null if it is no namespace. Note: In Firefox 3.5 and earlier, HTML elements are in no namespace. In later versions, HTML elements are in the http://www.w3.org/1999/xhtml namespace in both HTML and XML trees.
NonDocumentTypeChildNode.nextElementSibling Read only
Element, the element immediately following the given one in the tree, or null if there's no sibling node.Element.outerHTMLDOMString representing the markup of the element including its content. When used as a setter, replaces the element with nodes parsed from the given string.Element.prefix Read only
DOMString representing the namespace prefix of the element, or null if no prefix is specified.NonDocumentTypeChildNode.previousElementSibling Read only
Element, the element immediately preceding the given one in the tree, or null if there is no sibling element.Element.scrollHeight Read only
Number representing the scroll view height of an element.Element.scrollLeftNumber representing the left scroll offset of the element.Element.scrollLeftMax Read only
Number representing the maximum left scroll offset possible for the element.Element.scrollTopNumber representing number of pixels the top of the document is scrolled vertically.Element.scrollTopMax Read only
Number representing the maximum top scroll offset possible for the element.Element.scrollWidth Read only
Number representing the scroll view width of the element.Element.shadowRootRead only
Element.openOrClosedShadowRoot Read only
Element.slot
Element.tabStop
Boolean indicating if the element can receive input focus via the tab key.Element.tagName Read only
String with the name of the tag for the given element.Element.undoManager Read only
UndoManager associated with the element.Element.undoScope
Boolean indicating if the element is an undo scope host, or not.Note: DOM Level 3 defined namespaceURI, localName and prefix on the Node interface. In DOM4 they were moved to Element.
This change is implemented in Chrome since version 46.0 and Firefox since version 48.0.
The Element interface includes the following property, defined on the Slotable mixin.
Slotable.assignedSlotRead only
HTMLSlotElement representing the <slot> the node is inserted in.Element.onfullscreenchangefullscreenchange event, which is sent when the element enters or exits full-screen mode. This can be used to watch both for successful expected transitions, but also to watch for unexpected changes, such as when your app is backgrounded.Element.onfullscreenerrorfullscreenerror event, which is sent when an error occurs while attempting to change into full-screen mode.Element.onwheelwheel event. This is now implemented on GlobalEventHandlers.
Inherits methods from its parents Node, and its own parent, EventTarget, and implements those of ParentNode, ChildNode, NonDocumentTypeChildNode, and Animatable.
EventTarget.addEventListener()Element.attachShadow()ShadowRoot.Element.animate()
Element.closest()
Element which is the closest ancestor of the current element (or the current element itself) which matches the selectors given in parameter.Element.createShadowRoot()
ShadowRoot.Element.computedStyleMap()
StylePropertyMapReadOnly interface which provides a read-only representation of a CSS declaration block that is an alternative to CSSStyleDeclaration.EventTarget.dispatchEvent()Boolean that indicates whether no handler canceled the event.Element.getAnimations()
Element.getAttribute()Object.Element.getAttributeNames()Element.getAttributeNS()Object.Element.getAttributeNode()
Attr.Element.getAttributeNodeNS()
Attr.Element.getBoundingClientRect()Element.getClientRects()Element.getElementsByClassName()HTMLCollection that contains all descendants of the current element that possess the list of classes given in the parameter.Element.getElementsByTagName()HTMLCollection containing all descendant elements, of a particular tag name, from the current element.Element.getElementsByTagNameNS()HTMLCollection containing all descendant elements, of a particular tag name and namespace, from the current element.Element.hasAttribute()Boolean indicating if the element has the specified attribute or not.Element.hasAttributeNS()Boolean indicating if the element has the specified attribute, in the specified namespace, or not.Element.hasAttributes()Boolean indicating if the element has one or more HTML attributes present.Element.hasPointerCapture()Element.insertAdjacentElement()Element.insertAdjacentHTML()Element.insertAdjacentText()Element.matches()
Boolean indicating whether or not the element would be selected by the specified selector string.Element.querySelector()Node which matches the specified selector string relative to the element.Element.querySelectorAll()NodeList of nodes which match the specified selector string relative to the element.Element.releasePointerCapture()pointer event.ChildNode.remove()
Element.removeAttribute()Element.removeAttributeNS()Element.removeAttributeNode()
EventTarget.removeEventListener()Element.requestFullscreen()
Element.requestPointerLock()
Element.scroll()Element.scrollBy()Element.scrollIntoView()
Element.scrollTo()Element.setAttribute()Element.setAttributeNS()Element.setAttributeNode()
Element.setAttributeNodeNS()
Element.setCapture()
Element.setPointerCapture()Element.toggleAttribute()| Specification | Status | Comment |
|---|---|---|
| Web Animations | Working Draft | Added the getAnimations() method. |
| UndoManager and DOMTransaction The definition of 'Element' in that specification. | Editor's Draft | Added the undoScope and undoManager properties. |
| Pointer Events – Level 2 The definition of 'Element' in that specification. | Working Draft | Added the following event handlers: ongotpointercapture and onlostpointercapture.Added the following methods: setPointerCapture() and releasePointerCapture(). |
| Pointer Events The definition of 'Element' in that specification. | Recommendation | Added the following event handlers: ongotpointercapture and onlostpointercapture.Added the following methods: setPointerCapture() and releasePointerCapture(). |
| Selectors API Level 1 The definition of 'Element' in that specification. | Obsolete | Added the following methods: querySelector() and querySelectorAll(). |
| Pointer Lock The definition of 'Element' in that specification. | Candidate Recommendation | Added the requestPointerLock() method. |
| Fullscreen API The definition of 'Element' in that specification. | Living Standard | Added the requestFullscreen() method. |
| DOM Parsing and Serialization The definition of 'Element' in that specification. | Working Draft | Added the following properties: innerHTML, and outerHTML.Added the following method: insertAdjacentHTML(). |
| CSS Object Model (CSSOM) View Module The definition of 'Element' in that specification. | Working Draft | Added the following properties: scrollTop, scrollLeft, scrollWidth, scrollHeight, clientTop, clientLeft, clientWidth, and clientHeight.Added the following methods: getClientRects(), getBoundingClientRect(), scroll(), scrollBy(), scrollTo() and scrollIntoView(). |
| Element Traversal Specification The definition of 'Element' in that specification. | Obsolete | Added inheritance of the ElementTraversal interface. |
| DOM The definition of 'Element' in that specification. | Living Standard | Added the following methods: closest(), insertAdjacentElement() and insertAdjacentText().Moved hasAttributes() from the Node interface to this one. |
| DOM4 The definition of 'Element' in that specification. | Obsolete | Removed the following methods: setIdAttribute(), setIdAttributeNS(), and setIdAttributeNode().Modified the return value of getElementsByTagName() and getElementsByTagNameNS().Removed the schemaTypeInfo property. |
| Document Object Model (DOM) Level 3 Core Specification The definition of 'Element' in that specification. | Obsolete | Added the following methods: setIdAttribute(), setIdAttributeNS(), and setIdAttributeNode(). These methods were never implemented and have been removed in later specifications.Added the schemaTypeInfo property. This property was never implemented and has been removed in later specifications. |
| Document Object Model (DOM) Level 2 Core Specification The definition of 'Element' in that specification. | Obsolete | The normalize() method has been moved to Node. |
| Document Object Model (DOM) Level 1 Specification The definition of 'Element' in that specification. | Obsolete | Initial definition. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 1 | Yes | 1 | Yes | Yes | Yes |
accessKey |
No
|
? | ? | ? | No
|
? |
animate
|
36 | No | 48 | No | 23 | No |
attachShadow |
53 | No | 63
|
No | 40 | 10 |
attributes |
26 | No | 22 | ? | ? | ? |
classList |
8 | 16
|
3.6 | 10 | Yes | 5.1 |
className |
Yes | Yes | Yes | Yes | Yes | Yes |
clientHeight |
Yes | Yes | Yes | 6 | Yes | Yes |
clientLeft |
Yes | ? | ? | ? | Yes | ? |
clientTop |
Yes | ? | ? | ? | Yes | ? |
clientWidth |
Yes | Yes | Yes | 6 | Yes | Yes |
closest |
41 | 15 | 35 | No | 28 | 9 |
computedStyleMap
|
66 | No | No | No | 53 | No |
createShadowRoot
|
35
|
No | 59 — 61
|
No | 22
|
No |
currentStyle
|
No | No | No | 6 | No | No |
getAttribute |
29 | Yes | 23 | Yes | Yes | 6 |
getAttributeNS |
Yes | Yes | Yes
|
Yes | Yes | Yes |
getAttributeNames |
61 | 18 | 45 | No | 48 | 9 |
getAttributeNode |
Yes | ? | ? | ? | Yes | ? |
getAttributeNodeNS |
Yes | ? | ? | ? | Yes | ? |
getBoundingClientRect |
Yes | Yes | 3 | 4 | Yes | 4 |
getClientRects |
Yes | ? | ? | ? | Yes | ? |
getElementsByClassName |
Yes | ? | Yes
|
9 | Yes | Yes
|
getElementsByTagName |
1
|
Yes | Yes
|
5.5 | Yes
|
Yes
|
getElementsByTagNameNS |
1
|
Yes | Yes
|
5.5 | Yes
|
Yes
|
hasAttribute |
Yes | Yes | Yes | Yes | Yes | Yes |
hasAttributeNS |
Yes | ? | ? | ? | Yes | ? |
hasAttributes |
Yes | ? | Yes
|
9 | Yes | Yes |
id |
Yes | Yes | Yes | Yes | Yes | Yes |
innerHTML |
1 | 12 | 1 | 4 | 7 | Yes |
insertAdjacentElement |
1 | 12 | 48 | Yes | Yes | Yes |
insertAdjacentHTML |
1 | 12 | 8 | 4
|
7 | 4 |
insertAdjacentText |
1 | 12 | 48 | Yes | Yes | Yes |
localName |
46
|
? | 48
|
? | Yes | ? |
matches |
34
|
Yes
|
34
|
9
|
21
|
7
|
name |
No | ? | ? | ? | No | ? |
namespaceURI |
46
|
? | 48
|
? | Yes
|
? |
openOrClosedShadowRoot
|
No | No | 63
|
No | No | No |
onfullscreenchange |
57 | ? | 64 | ? | ? | ? |
onfullscreenerror |
57 | ? | 64 | ? | ? | ? |
ongotpointercapture |
55 | ? | 59
|
11
|
42 | No |
onlostpointercapture |
55 | ? | 59
|
11
|
42 | No |
outerHTML |
Yes | Yes | 11 | 4 | 7 | 1.3 |
prefix |
46
|
Yes | 48
|
? | Yes | ? |
querySelector |
1 | 12 | 3.5 | 9
|
Yes | Yes |
querySelectorAll |
1 | Yes | 3.5 | 9
|
10 | 3.2 |
releasePointerCapture |
55 | ? | 59
|
11
|
42 | No |
removeAttribute |
Yes | ? | ? | ? | Yes | ? |
removeAttributeNS |
Yes | ? | ? | ? | Yes | ? |
removeAttributeNode |
Yes | ? | ? | ? | Yes | ? |
requestFullscreen |
15
|
Yes
|
64
|
11
|
15
|
Yes
|
requestPointerLock |
Yes
|
Yes | 50
|
? | ? | ? |
runtimeStyle
|
No | No | No | 6 | No | No |
scrollIntoView
|
29 | 12
|
1 | 8
|
38 | 5
|
scrollIntoViewIfNeeded
|
Yes | No | No | No | Yes | Yes |
scrollHeight |
4 | Yes | 21
|
8 | Yes | 4 |
scrollLeft |
Yes | Yes | Yes | Yes | Yes | Yes |
scrollLeftMax
|
No | No | 16 | No | No | No |
scrollTop |
Yes | Yes | Yes | Yes | Yes | Yes |
scrollTopMax
|
No | No | 16 | No | No | No |
scrollWidth |
Yes | ? | ? | ? | Yes | ? |
setAttribute |
Yes | ? | ? | ? | Yes | ? |
setAttributeNS |
Yes | ? | ? | ? | Yes | ? |
setAttributeNode |
Yes | ? | ? | ? | Yes | ? |
setAttributeNodeNS |
? | Yes
|
Yes | Yes
|
? | ? |
setCapture
|
No | ? | ? | ? | No | ? |
setPointerCapture |
55 | ? | 59
|
11
|
42 | No |
shadowRoot |
53 | No | 63
|
No | 40 | Yes |
slot |
53 | ? | ? | ? | ? | ? |
tabStop
|
43 | ? | ? | ? | ? | ? |
tagName |
Yes | Yes | Yes | Yes | Yes | Yes |
toggleAttribute |
69 | 18 | 63 | ? | 56 | ? |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | 18 | Yes | 4 | Yes | Yes | Yes |
accessKey |
No
|
No
|
? | ? | No
|
? | ? |
animate
|
37 | 36 | ? | 48 | 23 | ? | ? |
attachShadow |
53 | 53 | No | 63
|
40 | 10 | ? |
attributes |
Yes | Yes | ? | 22 | ? | ? | ? |
classList |
Yes | Yes | 12 | Yes | ? | 5 | ? |
className |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
clientHeight |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
clientLeft |
Yes | Yes | ? | ? | Yes | ? | ? |
clientTop |
Yes | Yes | ? | ? | Yes | ? | ? |
clientWidth |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
closest |
? | ? | ? | 35 | ? | 9 | ? |
computedStyleMap
|
66 | 66 | No | No | 53 | No | ? |
createShadowRoot
|
37
|
35
|
No | 59 — 61
|
22
|
No | 5.0
|
currentStyle
|
No | No | No | No | No | No | No |
getAttribute |
? | ? | ? | 23 | ? | ? | ? |
getAttributeNS |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
getAttributeNames |
61 | 61 | ? | 45 | 48 | ? | ? |
getAttributeNode |
Yes | Yes | ? | ? | Yes | ? | ? |
getAttributeNodeNS |
Yes | Yes | ? | ? | Yes | ? | ? |
getBoundingClientRect |
Yes | Yes | Yes | 4 | Yes | 4
|
? |
getClientRects |
Yes | Yes | ? | ? | Yes | ? | ? |
getElementsByClassName |
? | ? | ? | ? | ? | ? | ? |
getElementsByTagName |
Yes | ? | Yes | Yes
|
Yes | Yes | Yes |
getElementsByTagNameNS |
Yes | ? | Yes | Yes
|
Yes | Yes | ? |
hasAttribute |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
hasAttributeNS |
Yes | Yes | ? | ? | Yes | ? | ? |
hasAttributes |
? | ? | ? | ? | ? | ? | ? |
id |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
innerHTML |
Yes | 18 | 12 | 4 | Yes | 1 | 1.0 |
insertAdjacentElement |
2.3 | 18 | 12 | 48 | Yes | Yes | Yes |
insertAdjacentHTML |
2.3 | 18 | 12 | 8 | Yes | 4 | Yes |
insertAdjacentText |
2.3 | 18 | 12 | 48 | Yes | Yes | Yes |
localName |
? | ? | ? | 48
|
? | ? | ? |
matches |
Yes
|
34
|
Yes
|
34
|
21
|
8
|
Yes
|
name |
No | No | ? | ? | No | ? | ? |
namespaceURI |
? | ? | ? | Yes | ? | ? | ? |
openOrClosedShadowRoot
|
No | No | No | 63
|
No | No | No |
onfullscreenchange |
57 | 57 | ? | 64 | ? | ? | ? |
onfullscreenerror |
57 | 57 | ? | 64 | ? | ? | ? |
ongotpointercapture |
55 | 55 | ? | No
|
42 | No | ? |
onlostpointercapture |
55 | 55 | ? | No
|
42 | No | ? |
outerHTML |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
prefix |
? | ? | Yes | 48
|
? | ? | ? |
querySelector |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
querySelectorAll |
Yes | Yes | Yes | Yes | ? | Yes | Yes |
releasePointerCapture |
55 | 55 | ? | No
|
42 | No | ? |
removeAttribute |
Yes | Yes | ? | ? | Yes | ? | ? |
removeAttributeNS |
Yes | Yes | ? | ? | Yes | ? | ? |
removeAttributeNode |
Yes | Yes | ? | ? | Yes | ? | ? |
requestFullscreen |
Yes
|
Yes
|
Yes
|
64
|
14
|
Yes
|
Yes
|
requestPointerLock |
Yes
|
? | Yes | ? | ? | ? | ? |
runtimeStyle
|
No | No | No | No | No | No | No |
scrollIntoView
|
Yes | Yes | ? | 4 | Yes | 5
|
? |
scrollIntoViewIfNeeded
|
Yes | Yes | No | No | Yes | Yes | ? |
scrollHeight |
Yes | Yes | Yes | Yes | Yes | 4 | Yes |
scrollLeft |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
scrollLeftMax
|
No | No | No | 16 | No | No | No |
scrollTop |
Yes | Yes | Yes | Yes | Yes | Yes | Yes |
scrollTopMax
|
No | No | No | 16 | No | No | No |
scrollWidth |
Yes | Yes | ? | ? | Yes | ? | ? |
setAttribute |
Yes | Yes | ? | ? | Yes | ? | ? |
setAttributeNS |
Yes | Yes | ? | ? | Yes | ? | ? |
setAttributeNode |
Yes | Yes | ? | ? | Yes | ? | ? |
setAttributeNodeNS |
? | ? | ? | ? | ? | ? | ? |
setCapture
|
No | No | ? | ? | No | ? | ? |
setPointerCapture |
55 | 55 | ? | No
|
42 | No | ? |
shadowRoot |
53 | 53 | No | 63
|
40 | Yes | ? |
slot |
53 | 53 | ? | ? | ? | ? | ? |
tabStop
|
? | 43 | ? | ? | ? | ? | ? |
tagName |
? | ? | Yes | Yes | ? | ? | ? |
toggleAttribute |
69 | 69 | ? | 63 | 56 | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/element