跳转到主要内容

Element

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

For example, the HTMLElement interface is the base interface for HTML elements. Similarly, the SVGElement interface is the basis for all SVG elements, and the 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.

Instance properties

Element inherits properties from its parent interface, Node, and by extension that interface's parent, 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 Node, and its own parent, EventTarget.

Events

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

Animation events

Clipboard events

  • copy
    • : Fired when the user initiates a copy action through the browser's user interface.
  • cut
    • : Fired when the user initiates a cut action through the browser's user interface.
  • paste
    • : Fired when the user initiates a paste action through the browser's user interface.

Composition events

Focus events

  • blur
    • : Fired when an element has lost focus.
  • focus
    • : Fired when an element has gained focus.
  • focusin
    • : Fired when an element has gained focus, after focus.
  • focusout
    • : Fired when an element has lost focus, after blur.

Fullscreen events

Keyboard events

  • keydown
    • : Fired when a key is pressed.
  • keypress
    • : Fired when a key that produces a character value is pressed down.
  • keyup
    • : Fired when a key is released.

Mouse events

  • 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.
  • click
    • : Fired when a pointing device button (e.g., a mouse's primary button) is pressed and released on a single element.
  • contextmenu
    • : Fired when the user attempts to open a context menu.
  • dblclick
    • : Fired when a pointing device button (e.g., a mouse's primary button) is clicked twice on a single element.
  • DOMActivate
    • : Occurs when an element is activated, for instance, through a mouse click or a keypress.
  • 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.
  • mousedown
    • : Fired when a pointing device button is pressed on an element.
  • mouseenter
    • : Fired when a pointing device (usually a mouse) is moved over the element that has the listener attached.
  • 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.
  • mousemove
    • : Fired when a pointing device (usually a mouse) is moved while over an element.
  • 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.
  • mouseover
    • : Fired when a pointing device is moved onto the element to which the listener is attached or onto one of its children.
  • mouseup
    • : Fired when a pointing device button is released on an element.
  • mousewheel
    • : Fired when a mouse wheel or similar device is operated.
  • MozMousePixelScroll
    • : Fired when a mouse wheel or similar device is operated.
  • webkitmouseforcechanged
    • : Fired each time the amount of pressure changes on the trackpad touch screen.
  • webkitmouseforcedown
    • : Fired after the mousedown event as soon as sufficient pressure has been applied to qualify as a "force click".
  • webkitmouseforcewillbegin
  • webkitmouseforceup
    • : Fired after the webkitmouseforcedown event as soon as the pressure has been reduced sufficiently to end the "force click".

Pointer events

Scroll events

  • scroll
    • : Fired when the document view or an element has been scrolled.
  • scrollend
    • : Fires when the document view has completed scrolling.
  • scrollsnapchange
    • : Fired on the scroll container at the end of a scrolling operation when a new scroll snap target has been selected.
  • 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

  • gesturechange
    • : Fired when digits move during a touch gesture.
  • gestureend
    • : Fired when there are no longer multiple fingers contacting the touch surface, thus ending the gesture.
  • gesturestart
    • : Fired when multiple fingers contact the touch surface, thus starting a new gesture.
  • touchcancel
    • : Fired when one or more touch points have been disrupted in an implementation-specific manner (for example, too many touch points are created).
  • touchend
    • : Fired when one or more touch points are removed from the touch surface.
  • touchmove
    • : Fired when one or more touch points are moved along the touch surface.
  • touchstart
    • : Fired when one or more touch points are placed on the touch surface.

Transition events

Specifications

Browser compatibility