Element
Element
介面表示了一個在 Document
中的物件,其描述了各類型元素的共同屬性與方法,Element
的子介面則定義了不同類型元素的具體行為並增加額外的功能。例如 HTMLElement
為所有 HTML 元素的基礎介面,而 SVGElement
(en-US) 則是定義所有 SVG 元素的介面。
在 Web 領域之外,如 XUL 語言也能藉由 XULElement
介面來繼承 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.assignedSlot
(en-US) 實驗性質 Read only-
Returns the
HTMLSlotElement
(en-US) interface associated with the element. Element.attributes
Read only-
Returns a
NamedNodeMap
object containing the assigned attributes of the corresponding HTML element. Element.classList
Read only-
Returns a
DOMTokenList
containing the list of class attributes. Element.className
(en-US)-
Is a
DOMString
representing the class of the element. Element.clientHeight
實驗性質 Read only-
Returns a
Number
representing the inner height of the element. Element.clientLeft
(en-US) 實驗性質 Read only-
Returns a
Number
representing the width of the left border of the element. Element.clientTop
(en-US) 實驗性質 Read only-
Returns a
Number
representing the width of the top border of the element. Element.clientWidth
實驗性質 Read only-
Returns a
Number
representing the inner width of the element. Element.computedName
Read only-
Returns a
DOMString
containing the label exposed to accessibility. Element.computedRole
Read only-
Returns a
DOMString
containing the ARIA role that has been applied to a particular element. Element.id
(en-US)-
Is a
DOMString
representing the id of the element. Element.innerHTML
-
Is a
DOMString
representing the markup of the element's content. Element.localName
(en-US) Read only-
A
DOMString
representing the local part of the qualified name of the element. Element.namespaceURI
(en-US) Read only-
The namespace URI of the element, or
null
if it is no namespace.備註: 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
(en-US) Read only-
Is a
Element
, the element immediately following the given one in the tree, ornull
if there's no sibling node. Element.outerHTML
(en-US) 實驗性質-
Is a
DOMString
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
(en-US) Read only-
A
DOMString
representing the namespace prefix of the element, ornull
if no prefix is specified. NonDocumentTypeChildNode.previousElementSibling
(en-US) Read only-
Is a
Element
, the element immediately preceding the given one in the tree, ornull
if there is no sibling element. Element.scrollHeight
實驗性質 Read only-
Returns a
Number
representing the scroll view height of an element. Element.scrollLeft
(en-US) 實驗性質-
Is a
Number
representing the left scroll offset of the element. Element.scrollLeftMax
(en-US) 非標準 Read only-
Returns a
Number
representing the maximum left scroll offset possible for the element. Element.scrollTop
實驗性質-
Is a
Number
representing the top scroll offset the an element. Element.scrollTopMax
(en-US) 非標準 Read only-
Returns a
Number
representing the maximum top scroll offset possible for the element. Element.scrollWidth
(en-US) 實驗性質 Read only-
Returns a
Number
representing the scroll view width of the element. Element.shadowRoot
(en-US) 實驗性質 Read only-
Returns the youngest shadow root that is hosted by the element.
Element.slot
(en-US) 實驗性質-
Returns the name of the shadow DOM slot attatched to the element. A slot is a placeholder inside a web component that users can fill with their own markup.
Element.tabStop
(en-US) 非標準-
Is a
Boolean
indicating if the element can receive input focus via the tab key. Element.tagName
(en-US) Read only-
Returns a
String
with the name of the tag for the given element. Element.undoManager
實驗性質 Read only-
Returns the
UndoManager
associated with the element. Element.undoScope
實驗性質-
Is a
Boolean
indicating if the element is an undo scope host, or not.
備註: 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.
事件處理器
Element.ongotpointercapture
(en-US)-
Returns the event handler for the
gotpointercapture
event type. Element.onlostpointercapture
(en-US)-
Returns the event handler for the
lostpointercapture
event type. Element.onwheel
(en-US) 非標準-
Returns the event handling code for the
wheel
event.
方法
Inherits methods from its parents Node
, and its own parent, EventTarget
, and implements those of ParentNode
, ChildNode
, NonDocumentTypeChildNode
, and Animatable
.
EventTarget.addEventListener()
-
Registers an event handler to a specific event type on the element.
Element.attachShadow()
(en-US) 實驗性質-
Attatches a shadow DOM tree to the specified element and returns a reference to its
ShadowRoot
(en-US). Element.animate()
(en-US) 實驗性質-
A shortcut method to create and run an animation on an element. Returns the created Animation object instance.
Element.closest()
(en-US) 實驗性質-
Returns the
Element
, descendant of this element (or this element itself), that is the closest ancestor of the elements selected by the selectors given in parameter. Element.createShadowRoot()
(en-US) 實驗性質 已棄用-
Creates a shadow DOM (en-US) on on the element, turning it into a shadow host. Returns a
ShadowRoot
(en-US). EventTarget.dispatchEvent()
-
Dispatches an event to this node in the DOM and returns a
Boolean
that indicates that at least one handler has not canceled it. Element.find()
實驗性質-
...
Element.findAll()
實驗性質-
...
Element.getAnimations()
(en-US) 實驗性質-
Returns an array of Animation objects currently active on the element.
Element.getAttribute()
-
Retrieves the value of the named attribute from the current node and returns it as an
Object
. Element.getAttributeNames()
(en-US)-
TBD
Element.getAttributeNS()
(en-US)-
Retrieves the value of the attribute with the specified name and namespace, from the current node and returns it as an
Object
. Element.getAttributeNode()
(en-US) 已棄用-
Retrieves the node representation of the named attribute from the current node and returns it as an
Attr
(en-US). Element.getAttributeNodeNS()
(en-US) 已棄用-
Retrieves the node representation of the attribute with the specified name and namespace, from the current node and returns it as an
Attr
(en-US). Element.getBoundingClientRect()
(en-US)-
...
Element.getClientRects()
(en-US)-
Returns a collection of rectangles that indicate the bounding rectangles for each line of text in a client.
Element.getDestinationInsertionPoints()
實驗性質-
…
Element.getElementsByClassName()
(en-US)-
Returns a live
HTMLCollection
that contains all descendants of the current element that possess the list of classes given in the parameter. Element.getElementsByTagName()
(en-US)-
Returns a live
HTMLCollection
containing all descendant elements, of a particular tag name, from the current element. Element.getElementsByTagNameNS()
(en-US)-
Returns a live
HTMLCollection
containing all descendant elements, of a particular tag name and namespace, from the current element. Element.hasAttribute()
(en-US)-
Returns a
Boolean
indicating if the element has the specified attribute or not. Element.hasAttributeNS()
(en-US)-
Returns a
Boolean
indicating if the element has the specified attribute, in the specified namespace, or not. Element.hasAttributes()
(en-US)-
Returns a
Boolean
indicating if the element has one or more HTML attributes present. Element.insertAdjacentElement
(en-US) 實驗性質-
Inserts a given element node at a given position relative to the element it is invoked upon.
Element.insertAdjacentHTML
實驗性質-
Parses the text as HTML or XML and inserts the resulting nodes into the tree in the position given.
Element.insertAdjacentText
(en-US) 實驗性質-
Inserts a given text node at a given position relative to the element it is invoked upon.
Element.matches()
(en-US) 實驗性質-
Returns a
Boolean
indicating whether or not the element would be selected by the specified selector string. Element.querySelector()
(en-US)-
Returns the first
Node
which matches the specified selector string relative to the element. Element.querySelectorAll
-
Returns a
NodeList
of nodes which match the specified selector string relative to the element. Element.releasePointerCapture
(en-US)-
Releases (stops) pointer capture that was previously set for a specific
pointer event
(en-US). ChildNode.remove()
(en-US) 實驗性質-
Removes the element from the children list of its parent.
Element.removeAttribute()
(en-US)-
Removes the named attribute from the current node.
Element.removeAttributeNS()
(en-US)-
Removes the attribute with the specified name and namespace, from the current node.
Element.removeAttributeNode()
(en-US) 已棄用-
Removes the node representation of the named attribute from the current node.
EventTarget.removeEventListener()
-
Removes an event listener from the element.
Element.requestFullscreen()
(en-US) 實驗性質-
Asynchronously asks the browser to make the element full-screen.
Element.requestPointerLock()
(en-US) 實驗性質-
Allows to asynchronously ask for the pointer to be locked on the given element.
Element.scrollIntoView()
(en-US) 實驗性質-
Scrolls the page until the element gets into the view.
Element.setAttribute()
(en-US)-
Sets the value of a named attribute of the current node.
Element.setAttributeNS()
(en-US)-
Sets the value of the attribute with the specified name and namespace, from the current node.
Element.setAttributeNode()
(en-US) 已棄用-
Sets the node representation of the named attribute from the current node.
Element.setAttributeNodeNS()
(en-US) 已棄用-
Setw the node representation of the attribute with the specified name and namespace, from the current node.
Element.setCapture()
(en-US) 非標準-
Sets up mouse event capture, redirecting all mouse events to this element.
Element.setPointerCapture()
(en-US)-
Designates a specific element as the capture target of future
pointer events
(en-US).
規範
瀏覽器相容性
BCD tables only load in the browser