Skip to content

JavaScript event.type

The Event interface represents any event that occurs in the DOM; Some are generated by the user (such as mouse or keyboard events), others are produced by APIs (such as events that show whether an animation is working, videos are paused). There are many types of events, some of which use other interfaces based on the main Event interface. The event itself includes features and methods common to all events.

  • event.type: Returns the name of the event type when it is triggered.
  • event.currentTarget: The event listeners return the item that triggered the event.
  • event.target: Returns the element that triggered the event.
  • button: The read-only property indicates which mouse button is pressed to trigger the event.
  • The buttons: read-only property indicates which buttons are pressed on the mouse (or other input device) when the event is triggered.
  • event.timeStamp: Indicates the time that indicates when the event occurred.
  • event.clientX: Returns the horizontal coordinate of the mouse pointer over the current window when the mouse event is triggered.
  • event.clientY: Returns the vertical coordinate of the mouse pointer relative to the current window when the mouse event is triggered.
  • event.pageX:Returns the horizontal coordinate of the mouse pointer relative to the document when the mouse event is triggered.
  • event.pageY: Returns the vertical coordinate of the mouse pointer relative to the document when the mouse event is triggered
  • altKey: Returns whether the “ALT” key is pressed when a key event is triggered.
  • ctrlKey: Returns whether the “CTRL” key is pressed when a key event is triggered.
  • shiftKey: Returns whether the “SHIFT” key is pressed when a key event is triggered.
    event.type: Returns the name of the event type when it is triggered.
    event.currentTarget: The event listeners return the item that triggered the event.
    event.target: Returns the element that triggered the event.
    button: The read-only property indicates which mouse button is pressed to trigger the event.
    The buttons: read-only property indicates which buttons are pressed on the mouse (or other input device) when the event is triggered.
    event.timeStamp: Indicates the time that indicates when the event occurred.
    event.clientX: Returns the horizontal coordinate of the mouse pointer over the current window when the mouse event is triggered.
    event.clientY: Returns the vertical coordinate of the mouse pointer relative to the current window when the mouse event is triggered.
    event.pageX:Returns the horizontal coordinate of the mouse pointer relative to the document when the mouse event is triggered.
    event.pageY: Returns the vertical coordinate of the mouse pointer relative to the document when the mouse event is triggered
    altKey: Returns whether the “ALT” key is pressed when a key event is triggered.
    ctrlKey: Returns whether the “CTRL” key is pressed when a key event is triggered.
    shiftKey: Returns whether the “SHIFT” key is pressed when a key event is triggered. event.type: Returns the name of the event type when it is triggered.
  • event.currentTarget: The event listeners return the item that triggered the event.
  • event.target: Returns the element that triggered the event.
  • button: The read-only property indicates which mouse button is pressed to trigger the event.
  • The buttons: read-only property indicates which buttons are pressed on the mouse (or other input device) when the event is triggered.
  • event.timeStamp: Indicates the time that indicates when the event occurred.
  • event.clientX: Returns the horizontal coordinate of the mouse pointer over the current window when the mouse event is triggered.
  • event.clientY: Returns the vertical coordinate of the mouse pointer relative to the current window when the mouse event is triggered.
  • event.pageX:Returns the horizontal coordinate of the mouse pointer relative to the document when the mouse event is triggered.
  • event.pageY: Returns the vertical coordinate of the mouse pointer relative to the document when the mouse event is triggered
  • altKey: Returns whether the “ALT” key is pressed when a key event is triggered.
  • ctrlKey: Returns whether the “CTRL” key is pressed when a key event is triggered.
  • shiftKey: Returns whether the “SHIFT” key is pressed when a key event is triggered.

DOM Events event.type

The Event.type read-only property returns a string that contains the type of the event. It is determined when the event is created and becomes the name commonly used to specify a specific event, such as click, load or error.

Syntax:

event.type


event.type Examples

Example 1

event type example
    <body>

        <div id="box"
              onmousedown="eventFunction(event)"
              onmouseup="eventFunction(event)"
              onmouseout="eventFunction(event)"
              onmouseover="eventFunction(event)"></div>
        <div id="result"></div>

        <script>

            function eventFunction(e) {
                let type = e.type;
                document.getElementById("result").innerHTML = type;
            }
          
        </script>
    </body>

6 Comments »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: