HTMLElement
The HTMLElement interface represents any HTML element. Some elements directly implement this interface, others implement it via an interface that inherits it.
Properties
Inherits properties from its parent, Element, and implements those from GlobalEventHandlers andTouchEventHandlers.
HTMLElement.accessKey- Is a
DOMStringrepresenting the access key assigned to the element. HTMLElement.accessKeyLabelRead only- Returns a
DOMStringcontaining 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.isContentEditableRead only- Returns a
Booleanthat indicates whether or not the content of the element can be edited. HTMLElement.contextMenu- Is a
HTMLMenuElementrepresenting the contextual menu associated with the element. It may be null HTMLElement.datasetRead only- Returns a
DOMStringMapwith which script can read and write the element's custom data attributes (data-*) . HTMLElement.dir- Is a
DOMString, reflecting thedirglobal attribute, representing the directionality of the element. Possible values are"ltr","rtl", and"auto". HTMLElement.draggable- Is a
Booleanindicating if the element can be dragged. HTMLElement.dropzoneRead only- Returns a
DOMSettableTokenListreflecting thedropzoneglobal attribute and describing the behavior of the element regarding a drop operation. HTMLElement.hidden- Is a
Booleanindicating if the element is hidden or not. HTMLElement.itemScope- Is a
Booleanrepresenting the item scope. HTMLElement.itemTypeRead only- Returns a
DOMSettableTokenList… HTMLElement.itemId- Is a
DOMStringrepresenting the item ID. HTMLElement.itemRefRead only- Returns a
DOMSettableTokenList… HTMLElement.itemPropRead only- Returns a
DOMSettableTokenList… HTMLElement.itemValue- Returns a
Objectrepresenting the item value. HTMLElement.lang- Is a
DOMStringrepresenting the language of an element's attributes, text, and element contents. HTMLElement.offsetHeightRead only- Returns a
doublecontaining the height of an element, relative to the layout. HTMLElement.offsetLeftRead only- Returns a
double, the distance from this element's left border to itsoffsetParent's left border. HTMLElement.offsetParentRead only- Returns a
Elementthat is the element from which all offset calculations are currently computed. HTMLElement.offsetTopRead only- Returns a
double, the distance from this element's top border to itsoffsetParent's top border. HTMLElement.offsetWidthRead only- Returns a
doublecontaining the width of an element, relative to the layout. HTMLElement.propertiesRead only- Returns a
HTMLPropertiesCollection… HTMLElement.spellcheck- Is a
Booleanthat 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. HTMLElement.tabIndex- Is a
longrepresenting the position of the element in the tabbing order. HTMLElement.title- Is a
DOMStringcontaining the text that appears in a popup box when mouse is over the element. HTMLElement.translate- Is a
Booleanrepresenting the translation.
Event handlers
Most events properties, of the form onXYZ, are defined on the GlobalEventHandlers orTouchEventHandlers, implemented by HTMLElement. A few more are specific to HTMLElement.
HTMLElement.oncopy- Returns the event handling code for the
copyevent (bug 280959). HTMLElement.oncut- Returns the event handling code for the
cutevent (bug 280959). HTMLElement.onpaste- Returns the event handling code for the
pasteevent (bug 280959). TouchEventHandlers.ontouchstart- Returns the event handling code for the
touchstartevent. TouchEventHandlers.ontouchend- Returns the event handling code for the
touchendevent. TouchEventHandlers.ontouchmove- Returns the event handling code for the
touchmoveevent. TouchEventHandlers.ontouchenter- Returns the event handling code for the
touchenterevent. TouchEventHandlers.ontouchleave- Returns the event handling code for the
touchleaveevent. TouchEventHandlers.ontouchcancel- Returns the event handling code for the
touchcancelevent.
Methods
Inherits methods from its parent, Element.
HTMLElement.blur()- Removes keyboard focus from the currently focused element.
HTMLElement.click()- Sends a mouse click event to the element.
HTMLElement.focus()- Makes the element the current keyboard focus.
HTMLElement.forceSpellCheck()- Makes the spell checker runs on the element.
Specifications
| Specification | Status | Comment |
|---|---|---|
| CSS Object Model (CSSOM) View Module The definition of 'HTMLElement' in that specification. |
Working Draft | Added the following properties: offsetParent,offsetTop, offsetLeft, offsetWidth, andoffsetHeight. |
| WHATWG HTML Living Standard The definition of 'HTMLElement' in that specification. |
Living Standard | Added the following properties: translate, itemScope,itemType, itemId, itemRef, itemProp, properties, anditemValue.Added the following method: forceSpellcheck().Moved the onXYZ attributes to the GlobalEventHandlersinterface and added an inheritance from it. |
| HTML5 The definition of 'HTMLElement' in that specification. |
Recommendation | Added 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 Elementinterface. |
| Document Object Model (DOM) Level 2 HTML Specification The definition of 'HTMLElement' in that specification. |
Recommendation | No change from Document Object Model (DOM) Level 2 HTML Specification |
| Document Object Model (DOM) Level 1 Specification The definition of 'HTMLElement' in that specification. |
Recommendation | Initial definition. |
Browser compatibility
| Feature | Firefox (Gecko) | Chrome | Edge | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 1.0 (1.7 or earlier) | ? | (Yes) | ? | ? | ? |
accessKey |
5.0 (5.0) | 17.0 | (Yes) | ? | ? | 6.0 |
accessKeyLabel |
8.0 (8.0) | ? | No support | ? | ? | No supportWebKit bug 72715 |
blur() |
5.0 (5.0) | ? | (Yes) | 9 | ? | ? |
click() |
5.0 (5.0) | ?9 | (Yes) | 9 | ? | 6.0 |
dataset |
6.0 (6.0) | 8 | (Yes) | 11 | 11.10 | 5.1 |
focus() |
5.0 (5.0) | ? | (Yes) | 9 | ? | ? |
contentEditable |
3.0 (1.9) | (Yes) | (Yes) | 5.5 | 9 | (Yes) |
spellcheck |
2.0 (1.8.1) | ? | (Yes) | ? | ? | ? |
style |
(Yes) (returns aCSS2Properties, rather than a CSSStyleDeclaration) |
(Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
forceSpellCheck() |
No support | No support | No support | No support | No support | No support |
draggable |
(Yes) | ? | (Yes) | ? | 12.0 | ? |
dropzone |
No support | No support | No support | No support | 12.0 | No support |
offsetLeft, offsetTop,offsetParent, offsetHeightand offsetWidth |
(Yes) | ? | (Yes) | (Yes) | ? | ? |
translate |
No support | No support | No support | No support | No support | No support |
itemScope, itemType,itemRef, itemId, itemProp, and itemValue |
6.0 (6.0) | No support | No support | No support | 11.60 (Removed in Opera 15) |
No support |
properties |
(Yes) | ? | No support | ? | ? | ? |
HTMLElement.ontouchstart,HTMLElement.ontouchend,HTMLElement.ontouchmove,HTMLElement.ontouchenter,HTMLElement.ontouchleave, andHTMLElement.ontouchcancel |
(Yes) | (Yes) | No support | No support | ? | (Yes) |
HTMLElement.oncopy,HTMLElement.oncut, andHTMLElement.onpaste |
3.0 (1.9) | ? | (Yes) | ? | ? | ? |

浙公网安备 33010602011771号