--- title: Element slug: Web/API/Element tags: - API - DOM - DOM参考 - Element - 元素 - 参考 - 接口 translation_of: Web/API/Element ---
{{APIRef("DOM")}}
Element 是一个通用性非常强的基类,所有 {{DOMxRef("Document")}} 对象下的对象都继承自它。这个接口描述了所有相同种类的元素所普遍具有的方法和属性。一些接口继承自 Element 并且增加了一些额外功能的接口描述了具体的行为。例如, {{DOMxRef("HTMLElement")}} 接口是所有 HTML 元素的基本接口,而 {{DOMxRef("SVGElement")}} 接口是所有 SVG 元素的基础。大多数功能是在这个类的更深层级(hierarchy)的接口中被进一步制定的。
在 Web 平台的领域以外的语言,比如 XUL,通过 XULElement 接口,同样也实现了 Element 接口。
{{InheritanceDiagram}}
所有属性继承自它的祖先接口 {{DOMxRef("Node")}},并且扩展了 {{DOMxRef("Node")}} 的父接口 {{DOMxRef("EventTarget")}},并且从以下部分继承了属性:{{DOMxRef("ParentNode")}}、{{DOMxRef("ChildNode")}}、{{DOMxRef("NonDocumentTypeChildNode")}},和 {{DOMxRef("Animatable")}}。
null
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 no prefix is specified.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.
The Element interface includes the following property, defined on the {{DOMxRef("Slotable")}} mixin.
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")}}.
Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.
error{{DOMxRef("Element/fullscreenchange_event", "fullscreenchange")}}{{DOMxRef("Element/fullscreenerror_event", "fullscreenerror")}}Element if an error occurs while attempting to switch it into or out of full-screen mode.{{DOMxRef("Element/keydown_event", "keydown")}}{{DOMxRef("Element/keypress_event", "keypress")}}{{DOMxRef("Element/keyup_event", "keyup")}}| 规范文档 | 状态 | 说明 |
|---|---|---|
| {{SpecName("CSS4 Pseudo-Elements", '#window-interface', 'Element')}} | {{Spec2("CSS4 Pseudo-Elements")}} | Added the pseudo() method. |
| {{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 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(), scroll(), scrollBy(), scrollTo() 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')}} | Added the following methods: closest(), insertAdjacentElement() and insertAdjacentText().Moved hasAttributes() from the Node interface to this one. |
| {{SpecName("DOM4", "#interface-element", "Element")}} | {{Spec2("DOM4")}} | Removed the following methods: setIdAttribute(), setIdAttributeNS(), and setIdAttributeNode().Modified the return value of getElementsByTagName() and getElementsByTagNameNS().Removed the schemaTypeInfo property. |
| {{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. |
{{Compat("api.Element")}}