MDN Web Docs

Value

A string containing the type of Event.

Example

This example logs the event type whenever you press a keyboard key or click a mouse button.

HTML

html

<p>Press any key or click the mouse to get the event type.</p>
<p id="log"></p>

JavaScript

js

function getEventType(event) {
  const log = document.getElementById("log");
  log.innerText = `${event.type}\n${log.innerText}`;
}
// Keyboard events
document.addEventListener("keydown", getEventType); // first
document.addEventListener("keypress", getEventType); // second
document.addEventListener("keyup", getEventType); // third
// Mouse events
document.addEventListener("mousedown", getEventType); // first
document.addEventListener("mouseup", getEventType); // second
document.addEventListener("click", getEventType); // third

Result

Specifications

Specification
DOM
# ref-for-dom-event-type④

Browser compatibility

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗