jQuery event.type Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Events

Definition

event.type is a String that describes the nature of the event — "click", "keydown", or a custom name like "saveDraft". Since jQuery 1.0. It is the base name only (no namespace). Works with native events and .trigger().

Syntax

Start with these common calls. Keep them short and readable.

jQuery
event.type          // "click", "keydown", "saveDraft", …
event.namespace     // "myPlugin" for click.myPlugin (or "")

// Official pattern
$("a").on("click", function (event) {
  alert(event.type);   // "click"
});
CallWhat it does
event.typeLearn jQuery event.type: the String base event name (click, keydown, custom), official anchor alert demo, multi-event handlers, .trigger() customs, vs event.namespace, examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Bind with .on("click", fn) or multi: .on("click keydown", fn).
Step 2Inside the handler, read event.type.
Step 3Branch with if / switch when one function handles several events.

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official Anchor Click

Show event.type on every link click.

jQuery
$("a").on("click", function (event) {
  event.preventDefault();
  $("#out").text("event.type: " + event.type);
});
Try It Yourself

How It Works

  1. Bind click. All anchors share one handler.
  2. Prevent default. Stay on the page for the demo.
  3. Read type. Always the string "click".

Example 2 — Multi-Event Handler

One function for click, mouseenter, and mouseleave.

jQuery
$("#box").on("click mouseenter mouseleave", function (event) {
  $("#out").text("Fired: " + event.type);
});
Try It Yourself

How It Works

  1. One bind. Space-separated event list.
  2. Each fire. type matches that event.
  3. Shared logic. Log or branch without three handlers.

Example 3 — Custom saveDraft

Trigger a custom event; read its type in the handler.

jQuery
$("#editor").on("saveDraft", function (event) {
  $("#out").text("Draft saved (type: " + event.type + ")");
});

$("#save").on("click", function () {
  $("#editor").trigger("saveDraft");
});
Try It Yourself

How It Works

  1. Bind custom. Listen for saveDraft.
  2. Trigger. Button fires it on the editor.
  3. Type. Handler sees "saveDraft".

Frequently Asked Questions

event.type is a String on the jQuery event object. It describes the nature of the event — for example "click", "keydown", or a custom name like "saveDraft". Available since jQuery 1.0. It holds the base event name without any namespace suffix.
Bind click on anchors: $("a").on("click", function(event) { alert(event.type); }); // "click". The alert shows the base type string for every anchor click.
For a bind like click.myPlugin, event.type is "click" (the base name) and event.namespace is "myPlugin" (the dotted suffix). event.type never includes the namespace.
Yes. Bind .on("click mouseenter mouseleave", fn) and branch with event.type — each dispatch sets type to whichever event fired.
Yes. When you .trigger("saveDraft") or bind .on("saveDraft", fn), event.type is "saveDraft". jQuery sets type for native DOM events and custom triggers alike.
Usually yes for native DOM events. For synthetic jQuery triggers with no underlying DOM event, originalEvent may be undefined while event.type still holds the triggered name. Prefer event.type in jQuery handlers.

Next: event.pageX Property

Read the horizontal mouse position relative to the document.

event.pageX Property tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

10 people found this page helpful