HTMLElement
Interface HTMLElement
đại diện cho mọi phần tử HTML. Một vài phần tử sử dụng trực tiếp interface này, một vài phần tử khác lại sử dụng nó thông qua các lớp khác kế thừa nó.
Các thuộc tính
Được kế thừa từ Element
(en-US), và sử dụng chúng từ GlobalEventHandlers
(en-US) và TouchEventHandlers
.
HTMLElement.accessKey
(en-US)- Là một
DOMString
(en-US) trả về từ khoá truy cập được gán cho phần tử. HTMLElement.accessKeyLabel
(en-US) Read only- Trả về một
DOMString
(en-US) chứa các từ khoá truy cập đã được gán của phần tử. HTMLElement.contentEditable
(en-US)- Là một
DOMString
(en-US), nếu giá trị là"true"
, ta có thể chỉnh sửa phần tử này và ngược lại nếu giá trị là"false"
. HTMLElement.isContentEditable
(en-US) Read only- Trả về giá trị
Boolean
(en-US) cho biết nội dung của phần tử có được phép chỉnh sửa hay không. HTMLElement.contextMenu
(en-US)- Là một
HTMLMenuElement
(en-US) trả về một menu tóm lược liên kết các phần tử. Giá trị có thể lànull
. HTMLElement.dataset
Read only- Trả về một
DOMStringMap
(en-US) cho phép ta thao tác với các thuộc tính dữ liệu tùy biến của phần tử (data-*
) . HTMLElement.dir
(en-US)- Là một
DOMString
(en-US), tương tự với thuộc tính globaldir
, đại diện cho hướng hiển thị của phần tử. Các giá trị cho phép là"ltr"
,"rtl"
, và"auto"
. HTMLElement.draggable
- Có kiểu
Boolean
cho ta biết phần tử có thể được kéo (drag) hay không. HTMLElement.dropzone
Read only- Trả về một
DOMSettableTokenList
tương tự với thuộc tính globaldropzone
mô tả hành vi của phần tử liên quan đến hành động thả (drop). HTMLElement.hidden
(en-US)- Có kiểu
Boolean
cho ta biết phần tử có ẩn hay không. HTMLElement.inert
(en-US)- Có kiểu
Boolean
cho ta biết user agent must act as though the given node is absent đối với các sự kiện tương tác của người dùng, tìm kiếm văn bản trong trang, và lựa chọn văn bản. HTMLElement.innerText
(en-US)- Trả về nội dung văn bản được "render" từ một node và phần tử con của nó. Điều này tương tự với việc người dùng bôi đen văn bản và sao chép chúng.
HTMLElement.itemScope
- Có kiểu
Boolean
cho biết scope của item. HTMLElement.itemType
Read only- Trả về một
DOMSettableTokenList
… HTMLElement.itemId
- Là một
DOMString
(en-US) cho biết ID của item. HTMLElement.itemRef
Read only- Là một
DOMSettableTokenList
… HTMLElement.itemProp
Read only- Trả về một
DOMSettableTokenList
… HTMLElement.itemValue
- Trả về một
Object
cho biết giá trị của item. HTMLElement.lang
(en-US)- Là một
DOMString
(en-US) cho biết ngôn ngữ của thuộc tính của một phần tử, của văn bản và của nội dung phần tử đó. HTMLElement.noModule
- Có kiểu
Boolean
cho biết rằng việc nhúng đoạn script có thể được thực thi bởi user agent (có hỗ trợ module scripts) hay không. HTMLElement.nonce
(en-US)- 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
(en-US) Read only- Returns a
double
containing the height of an element, relative to the layout. HTMLElement.offsetLeft
(en-US)Read only- Returns a
double
, the distance from this element's left border to itsoffsetParent
's left border. HTMLElement.offsetParent
(en-US)Read only- Returns a
Element
(en-US) that is the element from which all offset calculations are currently computed. HTMLElement.offsetTop
(en-US)Read only- Returns a
double
, the distance from this element's top border to itsoffsetParent
's top border. HTMLElement.offsetWidth
(en-US)Read only- Returns a
double
containing the width of an element, relative to the layout. HTMLElement.properties
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
(en-US)- Is a
CSSStyleDeclaration
(en-US), an object representing the declarations of an element's style attributes. HTMLElement.tabIndex
(en-US)- Is a
long
representing the position of the element in the tabbing order. HTMLElement.title
(en-US)- Is a
DOMString
(en-US) containing the text that appears in a popup box when mouse is over the element. HTMLElement.translate
- Is a
Boolean
representing the translation.
Event handlers
Most event handler properties, of the form onXYZ
, are defined on the GlobalEventHandlers
(en-US) or TouchEventHandlers
interfaces and implemented by HTMLElement
. In addition, the following handlers are specific to HTMLElement
.
HTMLElement.oncopy
(en-US)- Returns the event handling code for the
copy
event (bug 280959). HTMLElement.oncut
(en-US)- Returns the event handling code for the
cut
event (bug 280959). HTMLElement.onpaste
(en-US)- Returns the event handling code for the
paste
event (bug 280959). TouchEventHandlers.ontouchstart
- Returns the event handling code for the
touchstart (en-US)
event. TouchEventHandlers.ontouchend
- Returns the event handling code for the
touchend (en-US)
event. TouchEventHandlers.ontouchmove
- Returns the event handling code for the
touchmove (en-US)
event. TouchEventHandlers.ontouchenter
- Returns the event handling code for the
touchenter
event. TouchEventHandlers.ontouchleave
- Returns the event handling code for the
touchleave
event. TouchEventHandlers.ontouchcancel
- Returns the event handling code for the
touchcancel (en-US)
event.
Các phương thức
Được kế thừa từ Element
(en-US).
HTMLElement.blur()
(en-US)- Bỏ truy cập phần tử hiện tại.
HTMLElement.click()
(en-US)- Gửi một sự kiện click chuột đến phần tử.
HTMLElement.focus()
(en-US)- Truy cập đến phần tử hiện tại (truy cập bằng cách click vào phần tử hoặc nhấn phím Tab để di chuyển đến).
HTMLElement.forceSpellCheck()
(en-US)- Kiểm tra chính tả nội dung của phần tử.
Các sự kiện
Bắt các sự kiện bằng cách sự dụng phương thức addEventListener()
hoặc bằng cách gán một thuộc tính sự sự kiện on_tên_sự_kiện
dựa trên interface này.
Các sự kiện animation
animationcancel
- Được gọi khi một animation dừng đột ngột.
Dùng tương tự với thuộc tínhonanimationcancel
. animationend
- Được gọi khi một animation kết thúc.
Dùng tương tự với thuộc tínhonanimationend
. animationiteration
- Được gọi khi một vòng lặp animation kết thúc.
Dùng tương tự với thuộc tínhonanimationiteration
. animationstart
- Fired when an animation starts.
Dùng tương tự với thuộc tínhonanimationstart
.
Các sự kiện input
beforeinput
- Được gọi khi giá trị của một phần tử <input> (en-US), <select> (en-US), hoặc <textarea> (en-US) sắp được chỉnh sửa.
input
- Được gọi khi giá trị của một phần tử <input> (en-US), <select> (en-US), hoặc <textarea> (en-US) đã được chỉnh sửa.
Dùng tương tự với thuộc tínhoninput
.
Pointer events
gotpointercapture
- Fired when an element captures a pointer using
setPointerCapture()
.
Also available via theongotpointercapture
property. lostpointercapture
- Fired when a captured pointer is released.
Also available via theonlostpointercapture
property. pointercancel
- Fired when a pointer event is canceled.
Also available via theonpointercancel
property. pointerdown
- Fired when a pointer becomes active.
Also available via theonpointerdown
property. pointerenter
- Fired when a pointer is moved into the hit test boundaries of an element or one of its descendants.
Also available via theonpointerenter
property. pointerleave
- Fired when a pointer is moved out of the hit test boundaries of an element.
Also available via theonpointerleave
property. pointermove
- Fired when a pointer changes coordinates.
Also available via theonpointermove
property. pointerout
- Fired when a pointer is moved out of the hit test boundaries of an element (among other reasons).
Also available via theonpointerout
property. pointerover
- Fired when a pointer is moved into an element's hit test boundaries.
Also available via theonpointerover
property. pointerup
- Fired when a pointer is no longer active.
Also available via theonpointerup
property.
Các sự kiện transition
transitioncancel
- Được gọi khi một CSS transition bị hủy.
Dùng tương tự với thuộc tínhontransitioncancel
. transitionend
- Được gọi khi một CSS transition hoàn thành.
Dùng tương tự với thuộc tínhontransitionend
. transitionrun
- Được gọi khi một CSS transition được tạo ra đầu tiên.
Dùng tương tự với thuộc tínhontransitionrun
. transitionstart
- Được gọi khi một CSS transition thực sự bắt đầu.
Dùng tương tự với thuộc tínhontransitionstart
.
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 , and offsetHeight . |
HTML Living Standard The definition of 'HTMLElement' in that specification. |
Living Standard | Added the following properties: translate , itemScope , itemType , itemId , itemRef , itemProp , properties , and itemValue .Added the following method: forceSpellcheck() .Moved the onXYZ attributes to the GlobalEventHandlers (en-US) interface 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 Element (en-US) interface. |
Document Object Model (DOM) Level 2 HTML Specification The definition of 'HTMLElement' in that specification. |
Obsolete | 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. |
Obsolete | Initial definition. |
Khả năng tương thích của trình duyệt
BCD tables only load in the browser