JavaScript Event type Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

The type property is a read-only string naming the event—like click, load, or error. It is set when the event is constructed. Learn MDN’s keyboard/mouse logger, shared handlers, and custom event names—with five examples and try-it labs.

01

Kind

Instance property

02

Type

string

03

Means

Event name

04

Set when

Constructed

05

Pairs with

addEventListener

06

Status

Baseline widely

Introduction

When you write element.addEventListener("click", handler), the string "click" is the event type. Inside the handler, event.type is that same name for the event that actually fired.

That is useful when one function handles several kinds of input—for example logging every keyboard and mouse stage, or branching on click vs keydown in shared UI code.

💡
Beginner tip

Event type strings are case-sensitive. Use "click", not "Click".

Understanding Event.type

An instance property that returns a string containing the event’s type—the name commonly used to refer to that event.

  • Examplesclick, load, error, keydown, submit.
  • Set at construction — for both built-in and new Event("name") events.
  • Read-only — you do not assign event.type = … later.
  • Matches listen name — same string you pass to addEventListener.
  • Baseline Widely available on MDN (since July 2015); also in Web Workers.

📝 Syntax

JavaScript
event.type

Value

A string containing the type of the Event.

Typical pattern

JavaScript
button.addEventListener("click", (event) => {
  console.log(event.type); // "click"
});

⚡ Quick Reference

GoalCode / note
Read nameevent.type
Branchif (event.type === "click")
ListenaddEventListener("click", fn)
Customnew Event("save") → type "save"
MDN statusBaseline Widely available (since July 2015)

🔍 At a Glance

Four facts to remember about Event.type.

Type
string

Read-only

Examples
click

load, error…

Case
exact

Case-sensitive

Baseline
widely

Since Jul 2015

Examples Gallery

Examples follow MDN Event: type. Use View Output or Try It Yourself.

📚 Getting Started

Read the type string and log several input events.

Example 1 — Read event.type

Click a button and log the type name.

JavaScript
button.addEventListener("click", (event) => {
  console.log(event.type); // "click"
});
Try It Yourself

How It Works

The string matches the name you registered with addEventListener.

Example 2 — Log Keyboard & Mouse Types (MDN)

One function prepends event.type for keys and mouse buttons.

JavaScript
function getEventType(event) {
  const log = document.getElementById("log");
  log.innerText = `${event.type}\n${log.innerText}`;
}

document.addEventListener("keydown", getEventType);
document.addEventListener("keypress", getEventType);
document.addEventListener("keyup", getEventType);

document.addEventListener("mousedown", getEventType);
document.addEventListener("mouseup", getEventType);
document.addEventListener("click", getEventType);
Try It Yourself

How It Works

A single click often fires mousedown, then mouseup, then click—each with its own type.

📈 Shared Handlers & Custom Names

Branch on type, invent custom events, and watch form events.

Example 3 — Shared Handler with switch

One function for both click and keydown.

JavaScript
function onInput(event) {
  switch (event.type) {
    case "click":
      out.textContent = "Mouse click";
      break;
    case "keydown":
      out.textContent = "Key: " + event.key;
      break;
    default:
      out.textContent = "Other: " + event.type;
  }
}

button.addEventListener("click", onInput);
window.addEventListener("keydown", onInput);
Try It Yourself

How It Works

event.type lets one function stay tidy instead of copying logic into two listeners.

Example 4 — Custom Event Type

Construct and dispatch an event named save.

JavaScript
const target = new EventTarget();

target.addEventListener("save", (event) => {
  console.log(event.type); // "save"
});

target.dispatchEvent(new Event("save"));
Try It Yourself

How It Works

The first argument to new Event(…) becomes event.type.

Example 5 — Form input vs change

Log which form event fired as you type and leave the field.

JavaScript
function logType(event) {
  out.textContent = event.type + " → " + event.target.value;
}

field.addEventListener("input", logType);
field.addEventListener("change", logType);
Try It Yourself

How It Works

input fires continuously; change usually fires when the value is committed (for example on blur).

🚀 Common Use Cases

  • Logging which event fired during debugging.
  • One handler for several related event names.
  • Custom application events (save, cart:update).
  • Teaching the link between addEventListener and the event object.
  • Analytics that tag interactions by type string.

🔧 How It Works

1

Event is constructed

Built-in UI action or new Event("name").

Create
2

Type is fixed

The name string is stored on the event object.

type
3

Listeners match the name

addEventListener("click", …) only gets click events.

Listen
4

Handler reads type

Shared functions branch on event.type.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Available in Web Workers.
  • Read-only string set when the event is constructed.
  • Case-sensitive; stick to standard lowercase DOM names.
  • Related learning: timeStamp, target, Event(), addEventListener(), JavaScript hub.

Universal Browser Support

Event.type is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. It is also available in Web Workers.

Baseline · Widely available

Event.type

Read-only string: the event’s name (click, load, error, custom names, and more).

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported (legacy)
Full support
Event.type Excellent

Bottom line: Use event.type to know which kind of event fired—especially in shared handlers and custom events.

Conclusion

Event.type is the event’s name as a string. It connects addEventListener, constructed events, and shared handlers that need to know what fired.

Continue with composedPath(), timeStamp, target, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Compare with exact lowercase strings
  • Reuse one handler when types are closely related
  • Pick clear custom names (save, cart:add)
  • Log type while learning event sequences
  • Keep listen names and construct names identical

❌ Don’t

  • Assign event.type after creation
  • Mix casing (Click vs click)
  • Assume every click is only one event type
  • Overload one mega-handler for unrelated types
  • Forget that custom types must be listened for explicitly

Key Takeaways

Knowledge Unlocked

Five things to remember about type

The event’s name string—set once, read often.

5
Core concepts
🎯02

Name

click, load…

Meaning
🔁03

Shared

switch on type

Pattern
⚙️04

Custom

new Event(name)

Create
🎯05

Baseline

since Jul 2015

Status

❓ Frequently Asked Questions

It is a read-only string on an Event that names the event—such as click, load, or error. It is set when the event is constructed.
No. MDN marks Event.type as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is also available in Web Workers.
The first argument to addEventListener (for example "click") is the type string you listen for. Inside the handler, event.type is that same name for the event that fired.
Yes. Attach the same function to several listeners (keydown, click, …) and branch with if (event.type === "click") or a switch.
new Event("save") or new CustomEvent("save") sets type to "save". You listen with addEventListener("save", …).
Yes. Use the exact lowercase names the DOM uses (click, not Click). Custom names should stay consistent too.
Did you know?

A physical mouse click is not one event type—it is usually a short sequence (mousedown, mouseup, click). Logging event.type is one of the easiest ways to see that sequence for yourself.

Next: composedPath()

See the full EventTarget array the event travels through.

composedPath() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful