jQuery event.namespace

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Event object · jQuery 1.4.3+

What You’ll Learn

event.namespace is a String property with the namespace from a namespaced bind like click.myPlugin or test.something. This tutorial covers the official demo, plugin patterns, .off('.namespace') cleanup, comparing with event.type, and custom events.

01

Property

event.namespace

02

Returns

String

03

Official

test.something

04

Bind

type.name

05

Plugins

.off cleanup

06

Since 1.4.3

Read-only

Introduction

jQuery lets you attach a namespace to event names by adding a dot suffix when binding: .on("click.myPlugin", fn). That keeps plugin handlers separate from app code and makes teardown easy with .off(".myPlugin").

Inside the handler, event.namespace tells you which namespace fired — useful when one function listens to several namespaced variants. jQuery has exposed this String property since version 1.4.3.

Understanding event.namespace

This property answers one question: which namespace was on the event that invoked this handler?

  • Namespaced bind.on("test.something", fn) sets event.namespace to "something".
  • No namespace — plain .on("click", fn) gives event.namespace as "" (empty string).
  • Read-only — a property, not a function; set by jQuery from the bind/trigger string.
  • Multiple segmentsclick.foo.bar can yield event.namespace of "foo.bar".
💡
Beginner Tip

event.type is the base name (click, test). event.namespace is everything after the first dot in the bind string. They work together — do not confuse the full string "click.myPlugin" with either property alone.

📝 Syntax

Official jQuery API form (since 1.4.3):

jQuery
event.namespace

// bind with a namespace:
$( "button" ).on( "click.myPlugin", function ( event ) {
  console.log( event.type );       // "click"
  console.log( event.namespace );  // "myPlugin"
});

Parameters

  • Nonenamespace is a property, not a method.

Return value

  • String — the namespace specified when the event was triggered; empty string when none was used.

Official jQuery API example

jQuery
$( "p" ).on( "test.something", function ( event ) {
  alert( event.namespace );
});

$( "button" ).on( "click", function () {
  $( "p" ).trigger( "test.something" );
});

⚡ Quick Reference

Bind stringevent.typeevent.namespace
"click"click""
"click.myPlugin"clickmyPlugin
"test.something"testsomething
"resize.widget.v2"resizewidget.v2
Remove namespace handlers.off(".myPlugin")

📋 event.namespace vs event.type vs bind string

Three related pieces — full bind name splits into type plus namespace.

Bind string
"click.myPlugin"

What you pass to .on()

event.type
event.type

Base event name

event.namespace
event.namespace

Suffix after first dot

.off cleanup
.off(".myPlugin")

Drop all handlers in namespace

Examples Gallery

Example 1 follows the official jQuery demo. Examples 2–5 cover plugins, cleanup, branching, and custom events.

📚 Official jQuery Demo

Trigger test.something and read namespace something.

Example 1 — Official Demo: alert namespace

Official jQuery demo — bind test.something, trigger it from a button, alert shows something.

jQuery
$( "p" ).on( "test.something", function ( event ) {
  alert( event.namespace );
});

$( "button" ).on( "click", function () {
  $( "p" ).trigger( "test.something" );
});
Try It Yourself

How It Works

jQuery parses test.something into type test and namespace something. The handler reads event.namespace — not the full bind string.

Example 2 — Plugin pattern: click.myPlugin

Bind a namespaced click so app code and plugin handlers coexist; log type and namespace separately.

jQuery
$( "#btn" ).on( "click.myPlugin", function ( event ) {
  console.log(
    "type:", event.type,
    "namespace:", event.namespace
  );
});

// App code can still use plain click:
$( "#btn" ).on( "click", function ( event ) {
  console.log( "app click — namespace:", event.namespace ); // ""
});
Try It Yourself

How It Works

Both handlers run on click — the plugin handler sees namespace myPlugin; the plain handler sees "".

📈 Practical Patterns

Teardown, branching, and custom event names.

Example 3 — Cleanup: .off(".myPlugin")

Remove every handler in a namespace without touching other binds — plugin destroy pattern.

jQuery
function initPlugin() {
  $( "#box" ).on( "click.myPlugin mouseenter.myPlugin", onPluginEvent );
}

function destroyPlugin() {
  $( "#box" ).off( ".myPlugin" );
}

function onPluginEvent( event ) {
  $( "#log" ).text( event.type + " — namespace: " + event.namespace );
}
Try It Yourself

How It Works

Namespaces group handlers for bulk removal. event.namespace confirms which suffix fired before teardown.

Example 4 — One handler, multiple namespaces

Shared utility bound to several namespaced events — branch on event.namespace.

jQuery
function onNotify( event ) {
  if ( event.namespace === "success" ) {
    $( "#toast" ).text( "Saved!" ).addClass( "ok" );
  } else if ( event.namespace === "error" ) {
    $( "#toast" ).text( "Failed." ).addClass( "err" );
  }
}

$( document ).on( "notify.success notify.error", onNotify );
$( "#ok" ).on( "click", function () { $( document ).trigger( "notify.success" ); });
$( "#bad" ).on( "click", function () { $( document ).trigger( "notify.error" ); });
Try It Yourself

How It Works

Same event.type (notify) with different namespaces routes one handler to different UI updates.

Example 5 — Widget lifecycle: refresh vs destroy

Custom widget events with namespaces — read namespace to run the right lifecycle hook.

jQuery
$( "#widget" ).on( "widget.refresh widget.destroy", function ( event ) {
  $( "#status" ).text(
    "widget." + event.namespace + " fired (type: " + event.type + ")"
  );
});

$( "#refresh" ).on( "click", function () {
  $( "#widget" ).trigger( "widget.refresh" );
});

$( "#destroy" ).on( "click", function () {
  $( "#widget" ).trigger( "widget.destroy" );
});
Try It Yourself

How It Works

Custom types plus namespaces keep lifecycle events organized — event.namespace identifies refresh vs destroy without separate handler functions.

🚀 Common Use Cases

  • jQuery plugins — bind click.myPlugin and tear down with .off(".myPlugin").
  • Shared handlers — branch on event.namespace for success vs error custom events.
  • Testing — assert namespace in unit tests after .trigger("type.ns").
  • Debugging — log type + namespace when many handlers share one element.
  • Widget APIs — expose refresh / destroy as namespaced custom events.
  • Avoid collisions — isolate third-party binds from application click handlers.

🧠 How event.namespace Works

1

Bind or trigger

You pass a dotted string — click.myPlugin or test.something — to .on() or .trigger().

Setup
2

jQuery parses

Splits into event.type (before first dot) and event.namespace (after).

Parse
3

Handler runs

Your callback reads event.namespace — a String, or "" if none.

Read
4

Plugin-safe code

Branch, log, or remove handlers by namespace without guessing bind strings.

📝 Notes

  • Available since jQuery 1.4.3 — returns a String.
  • Read-only property — not a function.
  • Empty namespace is "", not undefined or null.
  • Do not confuse with event.type — type is the base event name only.
  • .off(".namespace") removes handlers in that namespace across event types on the element.
  • Primarily used by plugin authors; app code benefits when sharing handlers across namespaced binds.

Browser Support

event.namespace is a jQuery-specific event object property since jQuery 1.4.3+. It is set by jQuery when namespaced binds or triggers run — independent of native DOM event names.

jQuery 1.4.3+ · all browsers

jQuery event.namespace

Read the namespace from namespaced events.

100% Universal
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
namespace String

Bottom line: Bind click.myPlugin — read event.namespace in the handler.

Conclusion

event.namespace exposes the dotted suffix from namespaced jQuery events — the official demo alerts something for test.something.

Use it with .off(".myPlugin") for plugin lifecycle, and pair with event.type when one handler serves multiple namespaced variants.

💡 Best Practices

✅ Do

  • Namespace plugin handlers — .on("click.myPlugin", fn)
  • Remove with .off(".myPlugin") on destroy
  • Log event.type and event.namespace together when debugging
  • Use unique namespace names per plugin (myWidget.v2)
  • Branch shared handlers with event.namespace === "success"

❌ Don’t

  • Call event.namespace() with parentheses
  • Assume namespace equals the full bind string
  • Forget empty string for non-namespaced handlers
  • Reuse generic namespaces like .plugin across libraries
  • Assign to event.namespace — it is read-only

Key Takeaways

Knowledge Unlocked

Five things to remember about namespace

Read the dotted suffix on jQuery events.

5
Core concepts
type 02

event.type

Base name

Pair
demo 03

Official

something

Demo
off 04

.off(".ns")

Cleanup

Use
plug 05

Plugins

Isolate binds

Why

❓ Frequently Asked Questions

event.namespace is a String property on the jQuery event object. It holds the namespace portion of the event that fired — for example, binding with .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), .on('test.something', handler), or .on('custom.widget', handler). The part after the first dot is stored in event.namespace (multiple segments join with dots).
event.type is the base event name — 'click', 'test', 'keydown'. event.namespace is only the suffix you added — 'myPlugin', 'something', or empty string '' when no namespace was used on the binding that fired.
Namespaces let plugins bind handlers without clobbering other code, remove all plugin handlers with .off('.myPlugin'), and branch in shared utilities using event.namespace — especially on custom events.
event.namespace is an empty string '' — not undefined. Check with if (event.namespace) or compare to a specific name like event.namespace === 'myPlugin'.
No. It is read-only — jQuery sets it from the namespaced bind string or trigger call that caused the handler to run. Use distinct bind names or trigger('type.namespace') to control it.
Did you know?

jQuery introduced namespaced events so multiple plugins could bind to the same element without overwriting each other. event.namespace (added in 1.4.3) lets a single handler function distinguish which dotted suffix fired — long before custom DOM events were widely used.

Next: event.type

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

event.type tutorial →

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.

6 people found this page helpful