event.type property

The event.type property contains the type of an event that occurred.

Syntax

javascriptevent.type;

Example

In the following example, a click handler is attached to an element, so the event type will be 'click':

html<button id="elem">button</button>
javascriptlet elem = document.querySelector('#elem');

elem.addEventListener('click', function(event) {
  console.log(event.type);
});

The code execution result:

javascript'click'

Example

In the following example, a focus loss handler is bound to an input, so the event type will be 'blur':

html<input id="elem">
javascriptlet elem = document.querySelector('#elem');

elem.addEventListener('blur', function(event) {
  console.log(event.type);
});

The code execution result:

javascript'blur'

See also

  • the target property
    that defines an element on which an event was assigned
  • the key property
    that obtains an entered character
  • the code property
    that obtains the code of a pressed key