跳转到主要内容

Element

{{APIRef("DOM")}}

Element is the most general base class from which all element objects (i.e., objects that represent elements) in a {{DOMxRef("Document")}}Document inherit. It only has methods and properties common to all kinds of elements. More specific classes inherit from Element.

For example, the {{DOMxRef("HTMLElement")}}HTMLElement interface is the base interface for HTML elements. Similarly, the {{DOMxRef("SVGElement")}}SVGElement interface is the basis for all SVG elements, and the {{DOMxRef("MathMLElement")}}MathMLElement interface is the base interface for MathML elements. Most functionality is specified further down the class hierarchy.

Languages outside the realm of the Web platform, like XUL through the XULElement interface, also implement Element.

{{InheritanceDiagram}}

Instance properties

Element inherits properties from its parent interface, {{DOMxRef("Node")}}Node, and by extension that interface's parent, {{DOMxRef("EventTarget")}}EventTarget.

Instance properties included from ARIA

The Element interface also includes the following properties.

Instance properties reflected from ARIA element references

The properties reflect the elements specified by id reference in the corresponding attributes, but with some caveats. See Reflected element references in the Reflected attributes guide for more information.

Instance methods

Element inherits methods from its parents {{DOMxRef("Node")}}Node, and its own parent, {{DOMxRef("EventTarget")}}EventTarget.

Events

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

  • {{domxref("Element/afterscriptexecute_event","afterscriptexecute")}} {{Non-standard_Inline}} {{deprecated_inline}}afterscriptexecute
    • : Fired when a script has been executed.
  • {{domxref("Element/beforeinput_event", "beforeinput")}}beforeinput
    • : Fired when the value of an input element is about to be modified.
  • {{domxref("Element/beforematch_event", "beforematch")}}beforematch
    • : Fires on an element that is in the hidden until found state, when the browser is about to reveal its content because the user has found the content through the "find in page" feature or through fragment navigation.
  • {{domxref("Element/beforescriptexecute_event","beforescriptexecute")}} {{Non-standard_Inline}} {{deprecated_inline}}beforescriptexecute
    • : Fired when a script is about to be executed.
  • {{domxref("Element/beforexrselect_event", "beforexrselect")}} {{Experimental_Inline}}beforexrselect
    • : Fired before WebXR select events ({{domxref("XRSession/select_event"select, "select")}}selectstart, {{domxref("XRSession/selectstart_event", "selectstart")}}, {{domxref("XRSession/selectend_event", "selectend")}}selectend) are dispatched.
  • {{domxref("Element/contentvisibilityautostatechange_event", "contentvisibilityautostatechange")}}contentvisibilityautostatechange
  • {{domxref("Element/input_event","input")}}input
    • : Fires when an element's value is changed as a direct result of a user action.
  • {{domxref("Element/securitypolicyviolation_event","securitypolicyviolation")}}securitypolicyviolation
  • {{domxref("Element/wheel_event","wheel")}}wheel
    • : Fired when the user rotates a wheel button on a pointing device (typically a mouse).

Animation events

  • {{domxref("Element/animationcancel_event", "animationcancel")}}animationcancel
    • : Fired when an animation unexpectedly aborts.
  • {{domxref("Element/animationend_event", "animationend")}}animationend
    • : Fired when an animation has completed normally.
  • {{domxref("Element/animationiteration_event", "animationiteration")}}animationiteration
    • : Fired when an animation iteration has completed.
  • {{domxref("Element/animationstart_event", "animationstart")}}animationstart
    • : Fired when an animation starts.

Clipboard events

  • {{domxref("Element/copy_event", "copy")}}copy
    • : Fired when the user initiates a copy action through the browser's user interface.
  • {{domxref("Element/cut_event", "cut")}}cut
    • : Fired when the user initiates a cut action through the browser's user interface.
  • {{domxref("Element/paste_event", "paste")}}paste
    • : Fired when the user initiates a paste action through the browser's user interface.

Composition events

  • {{domxref("Element/compositionend_event", "compositionend")}}compositionend
    • : Fired when a text composition system such as an {{glossary("input method editor")}}editor completes or cancels the current composition session.
  • {{domxref("Element/compositionstart_event", "compositionstart")}}compositionstart
  • {{domxref("Element/compositionupdate_event", "compositionupdate")}}compositionupdate
    • : Fired when a new character is received in the context of a text composition session controlled by a text composition system such as an {{glossary("input method editor")}}editor.

Focus events

  • {{domxref("Element/blur_event", "blur")}}blur
    • : Fired when an element has lost focus.
  • {{domxref("Element/focus_event", "focus")}}focus
    • : Fired when an element has gained focus.
  • {{domxref("Element/focusin_event", "focusin")}}focusin
    • : Fired when an element has gained focus, after {{domxref("Element/focus_event", "focus")}}focus.
  • {{domxref("Element/focusout_event", "focusout")}}focusout
    • : Fired when an element has lost focus, after {{domxref("Element/blur_event", "blur")}}blur.

Fullscreen events

  • {{domxref("Element/fullscreenchange_event", "fullscreenchange")}}fullscreenchange
    • : Sent to an Element when it transitions into or out of fullscreen mode.
  • {{domxref("Element/fullscreenerror_event", "fullscreenerror")}}fullscreenerror
    • : Sent to an Element if an error occurs while attempting to switch it into or out of fullscreen mode.

Keyboard events

  • {{domxref("Element/keydown_event", "keydown")}}keydown
    • : Fired when a key is pressed.
  • {{domxref("Element/keypress_event", "keypress")}} {{Deprecated_Inline}}keypress
    • : Fired when a key that produces a character value is pressed down.
  • {{domxref("Element/keyup_event", "keyup")}}keyup
    • : Fired when a key is released.

Mouse events

  • {{domxref("Element/auxclick_event", "auxclick")}}auxclick
    • : Fired when a non-primary pointing device button (e.g., any mouse button other than the left button) has been pressed and released on an element.
  • {{domxref("Element/click_event", "click")}}click
    • : Fired when a pointing device button (e.g., a mouse's primary button) is pressed and released on a single element.
  • {{domxref("Element/contextmenu_event", "contextmenu")}}contextmenu
    • : Fired when the user attempts to open a context menu.
  • {{domxref("Element/dblclick_event", "dblclick")}}dblclick
    • : Fired when a pointing device button (e.g., a mouse's primary button) is clicked twice on a single element.
  • {{domxref("Element/DOMActivate_event", "DOMActivate")}} {{Deprecated_Inline}}DOMActivate
    • : Occurs when an element is activated, for instance, through a mouse click or a keypress.
  • {{domxref("Element/DOMMouseScroll_event", "DOMMouseScroll")}} {{Deprecated_Inline}} {{Non-standard_Inline}}DOMMouseScroll
    • : Occurs when mouse wheel or similar device is operated and the accumulated scroll amount is over 1 line or 1 page since last event.
  • {{domxref("Element/mousedown_event", "mousedown")}}mousedown
    • : Fired when a pointing device button is pressed on an element.
  • {{domxref("Element/mouseenter_event", "mouseenter")}}mouseenter
    • : Fired when a pointing device (usually a mouse) is moved over the element that has the listener attached.
  • {{domxref("Element/mouseleave_event", "mouseleave")}}mouseleave
    • : Fired when the pointer of a pointing device (usually a mouse) is moved out of an element that has the listener attached to it.
  • {{domxref("Element/mousemove_event", "mousemove")}}mousemove
    • : Fired when a pointing device (usually a mouse) is moved while over an element.
  • {{domxref("Element/mouseout_event", "mouseout")}}mouseout
    • : Fired when a pointing device (usually a mouse) is moved off the element to which the listener is attached or off one of its children.
  • {{domxref("Element/mouseover_event", "mouseover")}}mouseover
    • : Fired when a pointing device is moved onto the element to which the listener is attached or onto one of its children.
  • {{domxref("Element/mouseup_event", "mouseup")}}mouseup
    • : Fired when a pointing device button is released on an element.
  • {{domxref("Element/mousewheel_event", "mousewheel")}} {{Deprecated_Inline}} {{Non-standard_Inline}}mousewheel
    • : Fired when a mouse wheel or similar device is operated.
  • {{domxref("Element/MozMousePixelScroll_event", "MozMousePixelScroll")}} {{Deprecated_Inline}} {{Non-standard_Inline}}MozMousePixelScroll
    • : Fired when a mouse wheel or similar device is operated.
  • {{domxref("Element/webkitmouseforcechanged_event", "webkitmouseforcechanged")}} {{Non-standard_Inline}}webkitmouseforcechanged
    • : Fired each time the amount of pressure changes on the trackpad touch screen.
  • {{domxref("Element/webkitmouseforcedown_event", "webkitmouseforcedown")}} {{Non-standard_Inline}}webkitmouseforcedown
    • : Fired after the mousedown event as soon as sufficient pressure has been applied to qualify as a "force click".
  • {{domxref("Element/webkitmouseforcewillbegin_event", "webkitmouseforcewillbegin")}} {{Non-standard_Inline}}webkitmouseforcewillbegin
    • : Fired before the {{domxref("Element/mousedown_event", "mousedown")}}mousedown event.
  • {{domxref("Element/webkitmouseforceup_event", "webkitmouseforceup")}} {{Non-standard_Inline}}webkitmouseforceup
    • : Fired after the {{domxref("Element/webkitmouseforcedown_event", "webkitmouseforcedown")}}webkitmouseforcedown event as soon as the pressure has been reduced sufficiently to end the "force click".

Pointer events

  • {{domxref("Element/gotpointercapture_event", "gotpointercapture")}}gotpointercapture
    • : Fired when an element captures a pointer using {{domxref("Element/setPointerCapture", "setPointerCapture()")}}.
  • {{domxref("Element/lostpointercapture_event", "lostpointercapture")}}lostpointercapture
  • {{domxref("Element/pointercancel_event", "pointercancel")}}pointercancel
    • : Fired when a pointer event is canceled.
  • {{domxref("Element/pointerdown_event", "pointerdown")}}pointerdown
    • : Fired when a pointer becomes active.
  • {{domxref("Element/pointerenter_event", "pointerenter")}}pointerenter
    • : Fired when a pointer is moved into the hit test boundaries of an element or one of its descendants.
  • {{domxref("Element/pointerleave_event", "pointerleave")}}pointerleave
    • : Fired when a pointer is moved out of the hit test boundaries of an element.
  • {{domxref("Element/pointermove_event", "pointermove")}}pointermove
    • : Fired when a pointer changes coordinates.
  • {{domxref("Element/pointerout_event", "pointerout")}}pointerout
    • : Fired when a pointer is moved out of the hit test boundaries of an element (among other reasons).
  • {{domxref("Element/pointerover_event", "pointerover")}}pointerover
    • : Fired when a pointer is moved into an element's hit test boundaries.
  • {{domxref("Element/pointerrawupdate_event", "pointerrawupdate")}}pointerrawupdate
    • : Fired when a pointer changes any properties that don't fire {{domxref("Element/pointerdown_event", "pointerdown")}}pointerdown or {{domxref("Element/pointerup_event", "pointerup")}}pointerup events.
  • {{domxref("Element/pointerup_event", "pointerup")}}pointerup
    • : Fired when a pointer is no longer active.

Scroll events

  • {{domxref("Element/scroll_event", "scroll")}}scroll
    • : Fired when the document view or an element has been scrolled.
  • {{domxref("Element/scrollend_event", "scrollend")}}scrollend
    • : Fires when the document view has completed scrolling.
  • {{domxref("Element/scrollsnapchange_event", "scrollsnapchange")}} {{experimental_inline}}scrollsnapchange
    • : Fired on the scroll container at the end of a scrolling operation when a new scroll snap target has been selected.
  • {{domxref("Element/scrollsnapchanging_event", "scrollsnapchanging")}} {{experimental_inline}}scrollsnapchanging
    • : Fired on the scroll container when the browser determines a new scroll snap target is pending, i.e., it will be selected when the current scroll gesture ends.

Touch events

  • {{domxref("Element/gesturechange_event","gesturechange")}} {{Non-standard_Inline}}gesturechange
    • : Fired when digits move during a touch gesture.
  • {{domxref("Element/gestureend_event","gestureend")}} {{Non-standard_Inline}}gestureend
    • : Fired when there are no longer multiple fingers contacting the touch surface, thus ending the gesture.
  • {{domxref("Element/gesturestart_event","gesturestart")}} {{Non-standard_Inline}}gesturestart
    • : Fired when multiple fingers contact the touch surface, thus starting a new gesture.
  • {{domxref("Element/touchcancel_event", "touchcancel")}}touchcancel
    • : Fired when one or more touch points have been disrupted in an implementation-specific manner (for example, too many touch points are created).
  • {{domxref("Element/touchend_event", "touchend")}}touchend
    • : Fired when one or more touch points are removed from the touch surface.
  • {{domxref("Element/touchmove_event", "touchmove")}}touchmove
    • : Fired when one or more touch points are moved along the touch surface.
  • {{domxref("Element/touchstart_event", "touchstart")}}touchstart
    • : Fired when one or more touch points are placed on the touch surface.

Transition events

  • {{domxref("Element/transitioncancel_event", "transitioncancel")}}transitioncancel
  • {{domxref("Element/transitionend_event", "transitionend")}}transitionend
  • {{domxref("Element/transitionrun_event", "transitionrun")}}transitionrun
    • : An {{domxref("Event")}}Event fired when a CSS transition is created (i.e., when it is added to a set of running transitions), though not necessarily started.
  • {{domxref("Element/transitionstart_event", "transitionstart")}}transitionstart

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}