offline version v3


213 of 264 menu

event.type property

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

Syntax

event.type;

Example

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

<button id="elem">button</button> let elem = document.querySelector('#elem'); elem.addEventListener('click', function(event) { console.log(event.type); });

The code execution result:

'click'

Example

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

<input id="elem"> let elem = document.querySelector('#elem'); elem.addEventListener('blur', function(event) { console.log(event.type); });

The code execution result:

'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
enru