event.data is an optional object you pass when binding with .on(). jQuery attaches it to the event object so the handler can read custom fields. Added in jQuery 1.1.
Remember
event.data // Object from .on(..., data, handler) — or undefined
// Direct bind
$("#btn").on("click", { id: 42 }, function (event) {
event.data.id; // 42
});
// Delegation
$("#list").on("click", "li", { group: "A" }, handler);
// Official loop pattern — capture i per button
$("button").eq(i).on("click", { value: i }, handler);
Pass an object when you bind; read the same object inside the handler.
Build a plain object with the values you need ({ value: i }, { id: "save" }).
Pass it to .on() before the handler: .on("click", data, handler).
For delegation: .on("click", "button", data, handler).
Inside the handler, read event.data fields.
Do not confuse with .data() on elements — that is a different API.
Piece
Required?
Role
events
Yes
Event type string (e.g. "click")
selector
Optional
Delegation filter
data
Optional
Object → becomes event.data
handler
Yes
function(event) that reads event.data
Pseudocode
Pseudocode
data = { key: value } // optional object at bind time
element.on("click", data, handler)
// or: parent.on("click", "child", data, handler)
when event fires:
event.data = data // same object reference from bind
call handler(event)
handler may read event.data.key
// Loop trap (var i):
for i from 0 to 4:
button[i].on("click", { value: i }, handler)
// event.data.value is correct per button
// bare i inside handler is often 5 after the loop
Reference
Cheat Sheet
Keep these facts handy while wiring handlers with data.
Topic
Detail
Type
Object (or undefined if omitted)
Since
jQuery 1.1
Bind form
.on(events [, sel] [, data], handler)
Official demo
{ value: i } inside a for loop
vs .data()
Bind payload vs element storage
Shared object
Same reference for every fire of that bind
Mutates?
You can change properties — avoid surprise sharing
event.data. Comes from the object passed to .on().
Both useful. Element state vs handler bind context.
Pick. Use event.data for bind-time constants; use .data() for per-element values.
Edge Cases & Pitfalls
Watch for these when using event.data.
loop
var loop closures
Bare i after for (var i …) is usually the final value. Capture with { value: i } or use let.
undefined
No data → often undefined
If you omit eventData, guard before reading: if (event.data) { … }.
share
Same object reference
Mutating event.data changes the shared bind object for later fires. Prefer read-only use.
vs .data()
Not the same as .data()
event.data is bind payload; .data() stores values on elements.
Compatibility
Browser Support
event.data is a jQuery event-object feature (not a native DOM Event field). Available since jQuery 1.1 via .on() / legacy bind APIs. Works wherever your loaded jQuery version runs.
✓ Stable · jQuery API
event.data
Supported across jQuery 1.x–3.x. Prefer .on(events, data, handler) in modern code (jQuery 1.7+).
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
event.datajQuery 1.1+
Bottom line: Safe for production. Pass a plain object at bind time; read event.data inside the handler.
Analysis
Performance Notes
Approach
Cost
Best for
.on("click", data, fn)
Cheap
Constants / ids per handler
Delegated + shared data
Cheap
Many similar children
Huge objects on every bind
More memory
Keep payloads small
event.data is just a reference stored at bind time — almost free to read. Prefer small plain objects. For large per-element state, use .data() on the element instead.
Remember
Key Takeaways
Role: custom object attached when you bind with .on().
Loop fix:{ value: i } beats bare var i closures.
Read:event.data.key inside the handler.
Not .data(): bind payload ≠ element storage.
One line: pass a plain object to .on(), then read it as event.data.
Frequently Asked Questions
event.data is the optional object you pass when binding with .on() — for example .on("click", { value: 1 }, handler). jQuery attaches it to the event object so the handler can read event.data.value. Available since jQuery 1.1.
Use .on("click", { key: value }, function (event) { … }). Inside the handler, read event.data.key. For delegation: .on("click", "button", { key: value }, handler).
With var i in a loop, every handler often shares the same i — clicks show the final index. Passing { value: i } to .on() stores each iteration’s value on that handler’s event.data.
No. event.data is the object passed at bind time to .on(). .data() stores values on DOM elements. Handler context vs element storage — different APIs.
event.data is often undefined. Guard before reading fields: if (event.data) { … } or always pass an object when you rely on custom keys.
Bind-time eventData from .on() is what populates event.data on both user clicks and .trigger("click"). Extra arguments to .trigger("click", [x]) are additional handler parameters — not a replacement for bind-time data.