--- title: Element slug: Web/API/Element tags: - API - DOM - DOM Reference - Element - NeedsTranslation - TopicStub - Élément(2) translation_of: Web/API/Element ---
{{ APIRef("DOM") }}
Element
介面表示了一個在 {{domxref("Document")}} 中的物件,其描述了各類型元素的共同屬性與方法,Element
的子介面則定義了不同類型元素的具體行為並增加額外的功能。例如 {{domxref("HTMLElement")}} 為所有 HTML 元素的基礎介面,而 {{domxref("SVGElement")}} 則是定義所有 SVG 元素的介面。
在 Web 領域之外,如 XUL 語言也能藉由 XULElement
介面來繼承 Element
。
{{InheritanceDiagram}}
Inherits properties from its parent interface, {{domxref("Node")}}, and by extension that interface's parent, {{domxref("EventTarget")}}. It implements the properties of {{domxref("ParentNode")}}, {{domxref("ChildNode")}}, {{domxref("NonDocumentTypeChildNode")}}, and {{domxref("Animatable")}}.
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. {{ gecko_minversion_inline("1.9.2") }}
null
if there's no sibling node.null
if no prefix is specified.null
if there is no sibling element.Note: DOM Level 3 defined namespaceURI
, localName
and prefix
on the {{domxref("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.
wheel
event.Inherits methods from its parents {{domxref("Node")}}, and its own parent, {{domxref("EventTarget")}}, and implements those of {{domxref("ParentNode")}}, {{domxref("ChildNode")}}, {{domxref("NonDocumentTypeChildNode")}}, and {{domxref("Animatable")}}.
{{experimental_inline}}Specification | Status | Comment |
---|---|---|
{{SpecName('Shadow DOM')}} | {{Spec2('Shadow DOM')}} | |
{{SpecName("Web Animations", '', '')}} | {{Spec2("Web Animations")}} | Added the getAnimations() method. |
{{SpecName('Undo Manager', '', 'Element')}} | {{Spec2('Undo Manager')}} | Added the undoScope and undoManager properties. |
{{SpecName('Pointer Events 2', '#extensions-to-the-element-interface', 'Element')}} | {{Spec2('Pointer Events 2')}} | Added the following event handlers: ongotpointercapture and onlostpointercapture .Added the following methods: setPointerCapture() and releasePointerCapture() . |
{{SpecName('Pointer Events', '#extensions-to-the-element-interface', 'Element')}} | {{Spec2('Pointer Events')}} | Added the following event handlers: ongotpointercapture and onlostpointercapture .Added the following methods: setPointerCapture() and releasePointerCapture() . |
{{SpecName('Selectors API Level 2', '#interface-definitions', 'Element')}} | {{Spec2('Selectors API Level 2')}} | Added the following methods: matches() (implemented as mozMatchesSelector() ), find() , findAll() . |
{{SpecName('Selectors API Level 1', '#interface-definitions', 'Element')}} | {{Spec2('Selectors API Level 1')}} | Added the following methods: querySelector() and querySelectorAll() . |
{{SpecName('Pointer Lock', 'index.html#element-interface', 'Element')}} | {{Spec2('Pointer Lock')}} | Added the requestPointerLock() method. |
{{SpecName('Fullscreen', '#api', 'Element')}} | {{Spec2('Fullscreen')}} | Added the requestFullscreen() method. |
{{SpecName('DOM Parsing', '#extensions-to-the-element-interface', 'Element')}} | {{Spec2('DOM Parsing')}} | Added the following properties: innerHTML , and outerHTML .Added the following method: insertAdjacentHTML() . |
{{SpecName('CSSOM View', '#extensions-to-the-element-interface', 'Element')}} | {{Spec2('CSSOM View')}} | Added the following properties: scrollTop , scrollLeft , scrollWidth , scrollHeight , clientTop , clientLeft , clientWidth , and clientHeight .Added the following methods: getClientRects() , getBoundingClientRect() , and scrollIntoView() . |
{{SpecName('Element Traversal', '#ecmascript-bindings', 'Element')}} | {{Spec2('Element Traversal')}} | Added inheritance of the {{domxref("ElementTraversal")}} interface. |
{{SpecName('DOM WHATWG', '#interface-element', 'Element')}} | {{Spec2('DOM WHATWG')}} | Removed the following methods: closest() , setIdAttribute() , setIdAttributeNS() , and setIdAttributeNode() .Removed the schemaTypeInfo property.Modified the return value of getElementsByTag() and getElementsByTagNS() .Moved hasAttributes() from the Node interface to this one.Inserted insertAdjacentElement() and insertAdjacentText() . |
{{SpecName('DOM3 Core', 'core.html#ID-745549614', 'Element')}} | {{Spec2('DOM3 Core')}} | 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. |
{{SpecName('DOM2 Core', 'core.html#ID-745549614', 'Element')}} | {{Spec2('DOM2 Core')}} | The normalize() method has been moved to {{domxref("Node")}}. |
{{SpecName('DOM1', 'level-one-core.html#ID-745549614', 'Element')}} | {{Spec2('DOM1')}} | Initial definition. |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 1.0 | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | 1.0 |
children |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9")}} | 7.0 with a significant bug [1] 9.0 according to the spec |
{{CompatVersionUnknown}} | {{CompatNo}} |
childElementCount , nextElementSibling , previousElementSibling |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9.1")}} | 9.0 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
firstElementChild , lastElementChild |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9")}} | 9.0 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
classList |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9.2")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | |
outerHTML {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("11")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
clientLeft , clientTop {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9.1")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
getBoundingClientRect() , getClientRects() {{experimental_inline}} |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
querySelector() , querySelectorAll() |
1.0 | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9.1")}} | 8.0 | 10.0 | 3.2 (525.3) |
insertAdjacentHTML() {{experimental_inline}} |
1.0 | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("8")}} | 4.0 | 7.0 | 4.0 (527) |
setCapture() {{non-standard_inline}} |
{{CompatNo}} | {{CompatNo}} | {{CompatGeckoDesktop("2")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
oncopy , oncut , onpaste {{non-standard_inline}} |
{{CompatNo}} | {{CompatNo}} | {{CompatGeckoDesktop("1.9")}} | {{CompatVersionUnknown}} | {{CompatNo}} | |
onwheel {{non-standard_inline}} |
{{CompatNo}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("17")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
ongotpointercapture , onlostpointercapture , setPointerCapture() , and releasePointerCapture() |
{{CompatChrome(52.0)}} [4] | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} [3] | 10.0 | {{CompatNo}} | {{CompatNo}} |
matches() {{experimental_inline}} |
{{CompatVersionUnknown}} with the non-standard name webkitMatchesSelector |
{{CompatVersionUnknown}} {{property_prefix("webkit")}} {{property_prefix("ms")}} | {{CompatGeckoDesktop("1.9.2")}} with the non-standard name mozMatchesSelector {{CompatGeckoDesktop("34")}} with the standard name |
9.0 with the non-standard name msMatchesSelector |
11.5 with the non-standard name oMatchesSelector 15.0 with the non-standard name webkitMatchesSelector |
5.0 with the non-standard name webkitMatchesSelector |
find() and findAll() |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
requestPointerLock() |
16.0 {{property_prefix("webkit")}}, behind an about:flags 22.0 {{property_prefix("webkit")}} (with special cases, progressively lifted see [2]) |
{{CompatVersionUnknown}} | {{CompatGeckoDesktop("14")}}{{property_prefix("moz")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
requestFullscreen() |
14.0 {{property_prefix("webkit")}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("10")}} {{property_prefix("moz")}} | 11.0 {{property_prefix("ms")}} | 12.10 15.0 {{property_prefix("webkit")}} |
5.1 {{property_prefix("webkit")}} |
undoManager and undoScope |
{{CompatNo}} | {{CompatNo}} | {{CompatVersionUnknown}} (behind the dom.undo_manager.enabled pref) |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
attributes |
{{CompatUnknown}} | {{CompatNo}} | {{CompatGeckoDesktop("22")}} Before this it was available via the {{domxref("Node")}} interface that any element inherits. |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
scrollTopMax() and scrollLeftMax() |
{{CompatNo}} | {{CompatNo}} | {{CompatGeckoDesktop("16")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
closest() |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("35")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
hasAttributes() |
{{CompatVersionUnknown}} | {{CompatNo}} | {{CompatGeckoDesktop("1.0")}} (on the {{domxref("Node")}} interface) {{CompatGeckoDesktop("35")}} (on this interface |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
insertAdjacentElement() , insertAdjacentText() |
{{CompatVersionUnknown}} | {{CompatNo}} | {{CompatGeckoDesktop("48.0")}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
assignedSlot , attatchShadow , shadowRoot , and slot |
{{CompatChrome(53)}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
computedRole and computedName |
{{CompatChrome(41)}}[4] | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | 28[4] | {{CompatUnknown}} |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | 1.0 | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | 1.0 | ||
scrollTopMax() and scrollLeftMax() |
{{CompatNo}} | {{CompatNo}} | {{CompatGeckoMobile("16")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | ||
closest() |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("35")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | ||
hasAttributes() |
{{CompatVersionUnknown}} | {{CompatNo}} | {{CompatGeckoMobile("1.0")}} (on the {{domxref("Node")}} interface) {{CompatGeckoMobile("35")}} (on this interface |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | ||
insertAdjacentElement() , insertAdjacentText() |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("48.0")}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | ||
assignedSlot , attatchShadow , shadowRoot , and slot |
{{CompatNo}} | {{CompatChrome(53.0)}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatChrome(53)}} |
computedRole and computedName |
{{CompatNo}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | 28[4] | {{CompatUnknown}} | {{CompatNo}} |
[1] Internet Explorer 7 and 8 incorrectly return the comments as part of the children of an Element. This is fixed in Internet Explorer 9 and later.
[2] Chrome 16 allowed webkitRequestPointerLock()
only in fullscreen; Chrome 21 for trusted web site (permission asked); Chrome 22 allowed it by default for all same-origin document; Chrome 23 allowed it in sandboxed {{HTMLElement("iframe")}} if the non-standard value webkit-allow-pointer-lock
is set to the {{htmlattrxref("sandbox", "iframe")}} attribute.
[3] Implementation withdrawn. See {{Bug("1166347")}}.
[4] Behind a flag.