Event.type
The Event.type
read-only property returns a string containing the type of event. It is set when the event is constructed and is the name commonly used to refer to the specific event.
The event
argument of EventTarget.addEventListener()
and EventTarget.removeEventListener()
is case insensitive.
For a list of available event types, see the event reference
Syntax
JavaScript
Copy Code
event.type
Examples
JavaScript
Copy Code
var string = event.type;
JavaScript
Copy Code
<code><!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"></code> <code> <title>Event.type Example</title></code> <code> <script> var currEvent = null;</code> <code> function getEvtType(evt) { console.log("//Start------------getEvtType(evt)------------ ");</code> <code> currEvent = evt.type; console.log(currEvent);</code> <code> //document.getElementById("Etype").firstChild.nodeValue = currEvent; document.getElementById("Etype").innerHTML = currEvent;</code> <code> console.log("//End--------------getEvtType(evt)------------ "); }</code> <code> //Keyboard events document.addEventListener("keypress", getEvtType, false); //[second] </code> <code> document.addEventListener("keydown", getEvtType, false); //first document.addEventListener("keyup", getEvtType, false); //third</code> <code> //Mouse events document.addEventListener("click", getEvtType, false); // third</code> <code> document.addEventListener("mousedown", getEvtType, false); //first document.addEventListener("mouseup", getEvtType, false); //second</code> <code> </script> </head></code> <code><body></code> <code> <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></code> <code></body> </html></code>
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Event.type' in that specification. |
Living Standard | |
DOM4 The definition of 'Event.type' in that specification. |
Working Draft | |
Document Object Model (DOM) Level 2 Events Specification The definition of 'Event.type' in that specification. |
Recommendation | Initial definition. |
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/event/type