W3cubDocs

/DOM

Event.type

The Event.type read-only property returns a string containing the event's type. It is set when the event is constructed and is the name commonly used to refer to the specific event, such as click, load, or error

The event argument of EventTarget.addEventListener() and EventTarget.removeEventListener() is case insensitive.

For a list of available event types, see the event reference

Syntax

event.type

Examples

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <title>Event.type Example</title>

    <script>
        var currEvent;
        function getEvtType(evt) {
            console.group();

            currEvent = evt.type;
            console.log(currEvent);

            document.getElementById("Etype").innerHTML = currEvent;

            console.groupEnd();
        }

        //Keyboard events
        document.addEventListener("keypress", getEvtType, false); //[second]  

        document.addEventListener("keydown", getEvtType, false); //first
        document.addEventListener("keyup", getEvtType, false); //third

        //Mouse events
        document.addEventListener("click", getEvtType, false); // third

        document.addEventListener("mousedown", getEvtType, false); //first
        document.addEventListener("mouseup", getEvtType, false); //second

    </script>
</head>

<body>

<p>Press any key or click the mouse to get the event type.</p>
<p>Event type: <span id="Etype" style="color:red">-</span></p>

</body>
</html>

Result

Specifications

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Event/type