HTMLElement - Web APIs 编辑

The HTMLElement interface represents any HTML element. Some elements directly implement this interface, while others implement it via an interface that inherits it.

  <div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="/wiki/en-US/docs/Web/API/EventTarget" target="_top"><rect x="1" y="1" width="110" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text  x="56" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">EventTarget</text></a><polyline points="111,25  121,20  121,30  111,25" stroke="#D4DDE4" fill="none"/><line x1="121" y1="25" x2="151" y2="25" stroke="#D4DDE4"/><a xlink:href="/wiki/en-US/docs/Web/API/Node" target="_top"><rect x="151" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text  x="188.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Node</text></a><polyline points="226,25  236,20  236,30  226,25" stroke="#D4DDE4" fill="none"/><line x1="236" y1="25" x2="266" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/wiki/en-US/docs/Web/API/Element" target="_top"><rect x="266" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text  x="303.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Element</text></a><polyline points="341,25  351,20  351,30  341,25" stroke="#D4DDE4" fill="none"/><line x1="351" y1="25" x2="381" y2="25" stroke="#D4DDE4"/><a xlink:href="/wiki/en-US/docs/Web/API/HTMLElement" target="_top"><rect x="381" y="1" width="110" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text  x="436" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">HTMLElement</text></a></svg></div>
  a:hover text { fill: #0095DD; pointer-events: all;}

Properties

Inherits properties from its parent, Element, and implements those from DocumentAndElementEventHandlers, ElementCSSInlineStyle, GlobalEventHandlers, HTMLOrForeignElement and TouchEventHandlers.

HTMLElement.accessKey
Is a DOMString representing the access key assigned to the element.
HTMLElement.accessKeyLabel Read only
Returns a DOMString containing the element's assigned access key.
HTMLElement.contentEditable
Is a DOMString, where a value of true means the element is editable and a value of false means it isn't.
HTMLElement.isContentEditable Read only
Returns a Boolean that indicates whether or not the content of the element can be edited.
HTMLElement.contextMenu This deprecated API should no longer be used, but will probably still work.
Is a HTMLMenuElement representing the contextual menu associated with the element. It may be null.
HTMLOrForeignElement.dataset Read only
Returns a DOMStringMap with which script can read and write the element's custom data attributes (data-*) .
HTMLElement.dir
Is a DOMString, reflecting the dir global attribute, representing the directionality of the element. Possible values are "ltr", "rtl", and "auto".
HTMLElement.draggable
Is a Boolean indicating if the element can be dragged.
HTMLElement.hidden
Is a Boolean indicating if the element is hidden or not.
HTMLElement.inert
Is a Boolean indicating whether the user agent must act as though the given node is absent for the purposes of user interaction events, in-page text searches ("find in page"), and text selection.
HTMLElement.innerText
Represents the "rendered" text content of a node and its descendants. As a getter, it approximates the text the user would get if they highlighted the contents of the element with the cursor and then copied it to the clipboard.
HTMLElement.itemScope This is an experimental API that should not be used in production code.
Is a Boolean representing the item scope.
HTMLElement.itemType This is an experimental API that should not be used in production code.Read only
Returns a DOMSettableTokenList
HTMLElement.itemId This is an experimental API that should not be used in production code.
Is a DOMString representing the item ID.
HTMLElement.itemRef This is an experimental API that should not be used in production code.Read only
Returns a DOMSettableTokenList
HTMLElement.itemProp This is an experimental API that should not be used in production code.Read only
Returns a DOMSettableTokenList
HTMLElement.itemValue This is an experimental API that should not be used in production code.
Returns a Object representing the item value.
HTMLElement.lang
Is a DOMString representing the language of an element's attributes, text, and element contents.
HTMLElement.noModule
Is a Boolean indicating whether an import script can be executed in user agents that support module scripts.
HTMLOrForeignElement.nonce
Returns the cryptographic number used once that is used by Content Security Policy to determine whether a given fetch will be allowed to proceed.
HTMLElement.offsetHeight This is an experimental API that should not be used in production code.Read only
Returns a double containing the height of an element, relative to the layout.
HTMLElement.offsetLeft This is an experimental API that should not be used in production code.Read only
Returns a double, the distance from this element's left border to its offsetParent's left border.
HTMLElement.offsetParent This is an experimental API that should not be used in production code.Read only
Returns a Element that is the element from which all offset calculations are currently computed.
HTMLElement.offsetTop This is an experimental API that should not be used in production code.Read only
Returns a double, the distance from this element's top border to its offsetParent's top border.
HTMLElement.offsetWidth This is an experimental API that should not be used in production code.Read only
Returns a double containing the width of an element, relative to the layout.
HTMLElement.properties This is an experimental API that should not be used in production code.Read only
Returns a HTMLPropertiesCollection
HTMLElement.spellcheck
Is a Boolean that controls spell-checking. It is present on all HTML elements, though it doesn't have an effect on all of them.
HTMLElement.style
Is a CSSStyleDeclaration, an object representing the declarations of an element's style attributes.
HTMLOrForeignElement.tabIndex
Is a long representing the position of the element in the tabbing order.
HTMLElement.title
Is a DOMString containing the text that appears in a popup box when mouse is over the element.
HTMLElement.translate This is an experimental API that should not be used in production code.
Is a Boolean representing the translation.

Event handlers

Most event handler properties, of the form onXYZ, are defined on the DocumentAndElementEventHandlers, GlobalEventHandlers or TouchEventHandlers interfaces and implemented by HTMLElement. In addition, the following handlers are specific to HTMLElement.

HTMLElement.oncopy This API has not been standardized.
Returns the event handling code for the copy event (bug 280959).
HTMLElement.oncut This API has not been standardized.
Returns the event handling code for the cut event (bug 280959).
HTMLElement.onpaste This API has not been standardized.
Returns the event handling code for the paste event (bug 280959).
TouchEventHandlers.ontouchstart This API has not been standardized.
Returns the event handling code for the touchstart event.
TouchEventHandlers.ontouchend This API has not been standardized.
Returns the event handling code for the touchend event.
TouchEventHandlers.ontouchmove This API has not been standardized.
Returns the event handling code for the touchmove event.
TouchEventHandlers.ontouchenter This API has not been standardized.
Returns the event handling code for the touchenter event.
TouchEventHandlers.ontouchleave This API has not been standardized.
Returns the event handling code for the touchleave event.
TouchEventHandlers.ontouchcancel This API has not been standardized.
Returns the event handling code for the touchcancel event.

Methods

Inherits methods from its parent, Element, and implements those from DocumentAndElementEventHandlers, ElementCSSInlineStyle, GlobalEventHandlers, HTMLOrForeignElement and TouchEventHandlers.

HTMLElement.attachInternals() This is an experimental API that should not be used in production code.
Attaches an ElementInternals instance to the custom element.
HTMLOrForeignElement.blur()
Removes keyboard focus from the currently focused element.
HTMLElement.click()
Sends a mouse click event to the element.
HTMLOrForeignElement.focus()
Makes the element the current keyboard focus.
HTMLElement.forceSpellCheck() This is an experimental API that should not be used in production code.
Runs the spell checker on the element's contents.

Events

Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.

invalid
Fired when an element does not satisfy its constraints during constraint validation.
Also available via the oninvalid property.

Animation events

animationcancel
Fired when an animation unexpectedly aborts.
Also available via the onanimationcancel property.
animationend
Fired when an animation has completed normally.
Also available via the onanimationend property.
animationiteration
Fired when an animation iteration has completed.
Also available via the onanimationiteration property.
animationstart
Fired when an animation starts.
Also available via the onanimationstart property.

Input events

beforeinput
Fired when the value of an <input>, <select>, or <textarea> element is about to be modified.
input
Fired when the value of an <input>, <select>, or <textarea> element has been changed.
Also available via the oninput property.
change
Fired when the value of an <input>, <select>, or <textarea> element has been changed and committed by the user. Unlike the input event, the change event is not necessarily fired for each alteration to an element's value.

Pointer events

gotpointercapture
Fired when an element captures a pointer using setPointerCapture().
Also available via the ongotpointercapture property.
lostpointercapture
Fired when a captured pointer is released.
Also available via the onlostpointercapture property.
pointercancel
Fired when a pointer event is canceled.
Also available via the onpointercancel property.
pointerdown
Fired when a pointer becomes active.
Also available via the onpointerdown property.
pointerenter
Fired when a pointer is moved into the hit test boundaries of an element or one of its descendants.
Also available via the onpointerenter property.
pointerleave
Fired when a pointer is moved out of the hit test boundaries of an element.
Also available via the onpointerleave property.
pointermove
Fired when a pointer changes coordinates.
Also available via the onpointermove property.
pointerout
Fired when a pointer is moved out of the hit test boundaries of an element (among other reasons).
Also available via the onpointerout property.
pointerover
Fired when a pointer is moved into an element's hit test boundaries.
Also available via the onpointerover property.
pointerup
Fired when a pointer is no longer active.
Also available via the onpointerup property.

Transition events

transitioncancel
Fired when a CSS transition is canceled.
Also available via the ontransitioncancel property.
transitionend
Fired when a CSS transition has completed.
Also available via the ontransitionend property.
transitionrun
Fired when a CSS transition is first created.
Also available via the ontransitionrun property.
transitionstart
Fired when a CSS transition has actually started.
Also available via the ontransitionstart property.

Specifications

SpecificationStatusComment
CSS Object Model (CSSOM) View Module
The definition of 'HTMLElement' in that specification.
Working DraftAdded the following properties: offsetParent, offsetTop, offsetLeft, offsetWidth, and offsetHeight.
HTML Living Standard
The definition of 'HTMLElement' in that specification.
Living StandardAdded the following properties: translate, itemScope, itemType, itemId, itemRef, itemProp, properties, and itemValue.
Added the following method: forceSpellcheck().
Moved the onXYZ attributes to the GlobalEventHandlers interface and added an inheritance from it.
HTML5
The definition of 'HTMLElement' in that specification.
RecommendationAdded the following properties: dataset, hidden, tabIndex, accessKey, accessKeyLabel, draggable, dropzone, contentEditable, isContentEditable, contextMenu, spellcheck, commandType, commandLabel, commandIcon, commandHidden, commandDisabled, commandChecked, style, and all the onXYZ properties.
Moved the id and className properties to the Element interface.
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'HTMLElement' in that specification.
ObsoleteNo change from Document Object Model (DOM) Level 2 HTML Specification
Document Object Model (DOM) Level 1 Specification
The definition of 'HTMLElement' in that specification.
ObsoleteInitial definition.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:106 次

字数:45570

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文