jQuery event.namespace Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Events

Definition

event.namespace is a String on the jQuery event object. It holds the namespace from a namespaced bind or trigger (for example click.myPlugin → "myPlugin"). Added in jQuery 1.4.3. Mostly used by plugin authors to behave differently per namespace.

Syntax

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

jQuery
event.namespace   // String — read-only

.on("click.myPlugin", fn)  → namespace = "myPlugin"
.on("test.something", fn)  → namespace = "something"
.on("click", fn)           → namespace = ""

event.type       → base name ("click", "test")
.off(".myPlugin") → remove all handlers in that namespace
CallWhat it does
event.namespaceLearn jQuery event.namespace: read the namespace from binds like click.myPlugin, official test.something demo, plugin cleanup with .off('.namespace'), compare with event.type, examples, pitfalls, and FAQs.

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

Parameters

ParameterDescription
Step 1Pick a short namespace for your plugin or feature (for example myPlugin).
Step 2Bind with .on("click.myPlugin", handler) (or any event type).
Step 3Inside the handler, read event.namespace — and event.type for the base name.

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 Demo: Read the Namespace

Bind test.something, trigger it from a button, show event.namespace.

jQuery
$("#target").on("test.something", function (event) {
  $("#out").text('event.namespace = "' + event.namespace + '"');
});

$("#fire").on("click", function () {
  $("#target").trigger("test.something");
});
Try It Yourself

How It Works

  1. Bind. test.something splits into type test and namespace something.
  2. Trigger. The button calls .trigger("test.something") on #target.
  3. Read. The handler logs event.namespace — not the full bind string.

Example 2 — Plugin Pattern: click.myPlugin

Namespaced and plain click can share one element; namespaces stay separate.

jQuery
var lines = [];

$("#btn").on("click.myPlugin", function (event) {
  lines.push(
    "plugin: type=" + event.type +
    ", namespace=\"" + event.namespace + "\""
  );
});

$("#btn").on("click", function (event) {
  lines.push(
    "app: type=" + event.type +
    ", namespace=\"" + event.namespace + "\""
  );
  $("#out").text(lines.join("\n"));
  lines = [];
});
Try It Yourself

How It Works

  1. Plugin bind. click.myPlugin sets event.namespace to "myPlugin".
  2. App bind. Plain click sets event.namespace to "".
  3. One click. Both handlers run; each sees its own namespace.

Example 3 — Clean Up with .off(".myPlugin")

Init plugin handlers, then remove only that namespace.

jQuery
function onPlugin(event) {
  $("#out").text(event.type + " — " + event.namespace);
}

$("#init").on("click", function () {
  $("#box")
    .off(".myPlugin")
    .on("click.myPlugin mouseenter.myPlugin", onPlugin);
  $("#out").text("Plugin ready — click or hover the box.");
});

$("#destroy").on("click", function () {
  $("#box").off(".myPlugin");
  $("#out").text("Destroyed — .off('.myPlugin') removed handlers.");
});
Try It Yourself

How It Works

  1. Init. Bind click and mouseenter under .myPlugin.
  2. Interact. Handlers report event.type and event.namespace.
  3. Destroy. .off(".myPlugin") drops every handler in that namespace.

Frequently Asked Questions

event.namespace is a String on the jQuery event object. It holds the namespace from a namespaced bind or trigger — for example .on("click.myPlugin", fn) sets event.namespace to "myPlugin" when that handler runs. Available since jQuery 1.4.3.
Append a dot and name after the event type: .on("click.myPlugin", handler) or .on("test.something", handler). The part after the first dot is stored in event.namespace (extra segments stay as "foo.bar").
event.type is the base name — "click", "test", "keydown". event.namespace is only the suffix — "myPlugin", "something", or "" when the binding that fired had no namespace.
Namespaces keep plugin handlers separate from app code, let you remove them with .off(".myPlugin"), and let shared handlers branch with event.namespace — especially for custom events.
event.namespace is an empty string "" — not undefined. Check with if (event.namespace) or compare to a name like event.namespace === "myPlugin".
No. It is read-only — jQuery sets it from the namespaced bind or trigger that ran the handler. Control it with distinct bind names or .trigger("type.namespace").

Next: event.type Property

Read the base event name — click, keydown, or your custom trigger string.

event.type 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.

9 people found this page helpful