event.timeStamp records when the browser created the event — epoch milliseconds you can subtract to measure gaps between clicks or key presses. This tutorial covers the official consecutive-click demo, handler profiling, comparing with Date.getTime() and performance.now(), double-click detection, input throttling, and the Firefox caveat.
01
Property
event.timeStamp
02
Returns
Number (ms)
03
Official
Click delta
04
Profile
Handler timing
05
Not now
Event birth time
06
Since 1.2.6
All events
Fundamentals
Introduction
Every jQuery handler receives an event object. Among its properties, event.timeStamp answers: when did the browser create this event? The value is a number — milliseconds between that moment and January 1, 1970 (the Unix epoch). It is not updated while your handler runs; reading it twice inside the same callback returns the same number.
jQuery has exposed event.timeStamp since version 1.2.6. The official docs highlight profiling: store event.timeStamp at one point, read it again on a later event, and note the difference. The canonical demo compares consecutive clicks with diff = event.timeStamp - last. For current wall-clock time inside a handler, use (new Date).getTime() instead — not timeStamp.
Concept
Understanding event.timeStamp
event.timeStamp is the browser’s record of event creation time in epoch milliseconds:
Fixed per event — set when the browser dispatches the event; unchanged for the lifetime of that event object.
Comparable across events — subtract two timestamps to get milliseconds between user actions (clicks, keydowns).
Not handler “now” — if work delays your callback, timeStamp still reflects creation time, not when your code runs.
Profiling aid — official pattern: read at start and end of handler work, or compare consecutive events via a stored last variable.
💡
Beginner Tip
Need “right now” inside the handler? Call (new Date).getTime() or Date.now(). Need “when did this click happen?” or “ms since last click?” — use event.timeStamp and subtraction.
Foundation
📝 Syntax
Official jQuery API form (since 1.2.6):
jQuery
event.timeStamp
// read inside any .on() handler:
function handler( event ) {
var created = event.timeStamp;
console.log( "Event created at epoch ms:", created );
}
// consecutive events — official delta pattern:
var last;
$( "div" ).on( "click", function ( event ) {
if ( last ) {
var diff = event.timeStamp - last;
console.log( "ms since last:", diff );
}
last = event.timeStamp;
});
Type
Number — milliseconds since January 1, 1970 UTC at event creation.
Return value
Not a method — a read-only property on the event object passed to your handler.
Same value for the entire dispatch of that event — subtract across events, not across lines in one handler expecting “now”.
Official jQuery API example
jQuery
var last, diff;
$( "div" ).on( "click", function ( event ) {
if ( last ) {
diff = event.timeStamp - last;
$( "div" ).append( "time since last event: " + diff + " " );
} else {
$( "div" ).append( "Click again. " );
}
last = event.timeStamp;
});
Cheat Sheet
⚡ Quick Reference
API
Measures
Best for
event.timeStamp
Epoch ms at event creation
Gap between two user events
Date.getTime() / Date.now()
Epoch ms when you call it
Wall clock “now” in handler
performance.now()
Ms since navigation start
High-res work inside one handler
event.timeStamp - last
Ms between consecutive events
Throttle, double-click, click spacing
last = event.timeStamp
Store for next comparison
Official consecutive-click demo
Compare
📋 timeStamp vs Date.getTime() vs performance.now() vs Date.now()
Four timing APIs beginners mix up — each answers a different question.
timeStamp
event.timeStamp
When browser created this event (epoch ms)
Date.getTime()
(new Date).getTime()
Wall clock now when handler runs
Date.now()
Date.now()
Same epoch ms as getTime() — shorthand
performance.now()
performance.now()
Monotonic high-res timer for in-handler work
Hands-On
Examples Gallery
Example 1 follows the official consecutive-click demo. Examples 2–5 cover handler profiling, timeStamp vs wall clock, double-click interval detection, and keydown throttling.
📚 Official jQuery Demo
Measure milliseconds between consecutive clicks on a div.
Example 1 — Official Demo: time since last click on div
Official jQuery pattern — first click prompts “Click again.” Later clicks append time since last event: {diff} using event.timeStamp - last.
jQuery
var last, diff;
$( "div" ).on( "click", function ( event ) {
if ( last ) {
diff = event.timeStamp - last;
$( "div" ).append( "time since last event: " + diff + " " );
} else {
$( "div" ).append( "Click again. " );
}
last = event.timeStamp;
});
First click → "Click again."
Second click → "time since last event: 842 " (example ms)
Each click updates last = event.timeStamp for the next delta
How It Works
event.timeStamp is fixed when the browser creates each click event. Subtracting the previous stored value yields the gap between user actions — the official profiling pattern from the jQuery API docs.
Example 2 — Handler profiling: measure work at start vs end
Capture performance.now() at handler entry and exit for in-handler duration; log event.timeStamp once to show event birth time stays constant.
jQuery
$( "#run" ).on( "click", function ( event ) {
var t0 = performance.now();
var birth = event.timeStamp;
// simulate work
for ( var i = 0; i < 1e6; i++ ) {}
var t1 = performance.now();
$( "#log" ).html(
"event.timeStamp: " + birth + " " +
"handler work: " + ( t1 - t0 ).toFixed( 2 ) + " ms"
);
});
event.timeStamp: 1738123456789 (epoch ms at click creation)
handler work: 12.40 ms (performance.now() delta)
timeStamp does not advance during the loop — use performance.now() for handler duration
How It Works
The official docs suggest reading timeStamp at two points to note differences — across events that means subtracting stored values. Inside one handler, performance.now() measures elapsed work; event.timeStamp only records when the event was born.
📈 Practical Patterns
Wall clock comparison, double-click detection, and keyboard throttling.
Example 3 — timeStamp vs Date.getTime(): creation vs now
Log both values in the same handler — event.timeStamp is event birth time; (new Date).getTime() is wall clock when your code runs.
jQuery
$( "button" ).on( "click", function ( event ) {
var now = ( new Date ).getTime();
var lag = now - event.timeStamp;
$( "#log" ).html(
"event.timeStamp: " + event.timeStamp + " " +
"Date.getTime(): " + now + " " +
"handler lag: " + lag + " ms"
);
});
event.timeStamp: 1738123456789
Date.getTime(): 1738123456794
handler lag: 5 ms (small under normal conditions; larger if main thread is busy)
Use Date.getTime() for "now" — not timeStamp
How It Works
jQuery docs explicitly say: for current time inside a handler, use (new Date).getTime(). The gap now - event.timeStamp shows how long after event creation your handler actually ran — useful when debugging slow main-thread queues.
Example 4 — Double-click interval: rapid second click within ~300 ms
Track last click timestamp; when event.timeStamp - last < 300, treat as double-click.
First click → "Single click — click again quickly"
Second click within 300 ms → "Double-click detected (187 ms)"
Slow second click → treated as new single click
How It Works
Subtracting consecutive event.timeStamp values measures inter-click spacing without polling a clock. Reset lastClick after a double-click so a third click starts a fresh sequence.
Example 5 — Input throttle: ignore keydown if delta < 200 ms
Store last keydown event.timeStamp; skip handler body when events arrive faster than 200 ms apart.
jQuery
var lastKey = 0;
$( "#search" ).on( "keydown", function ( event ) {
if ( event.timeStamp - lastKey < 200 ) {
return;
}
lastKey = event.timeStamp;
$( "#status" ).text( "Handled key at " + lastKey );
});
Rapid key repeat → most keydowns ignored
Keys spaced ≥ 200 ms apart → #status updates each time
Same timeStamp delta pattern as the official click demo
How It Works
Early return when event.timeStamp - lastKey < 200 throttles expensive autocomplete or search logic. Update lastKey only when you actually handle the event — mirrors the official consecutive-event subtraction pattern.
Applications
🚀 Common Use Cases
Click spacing — official demo: diff = event.timeStamp - last between consecutive clicks.
Handler profiling — compare timestamps at two code points or use performance.now() inside one handler.
Double-click detection — threshold on event.timeStamp - lastClick (~300 ms).
Input throttling — ignore keydown/keyup when delta from last handled event is below 200 ms.
Event ordering — compare creation times when debugging race conditions between rapid events.
Debug lag — Date.now() - event.timeStamp shows queue delay before your handler ran.
🧠 How event.timeStamp Is Set
1
User action
Browser creates a native event (click, keydown, etc.) and stamps it with creation time in epoch milliseconds.
Trigger
2
jQuery normalizes
Your handler receives jQuery’s event object with event.timeStamp copied from the native event — a Number since 1.2.6.
Handler
3
Value stays fixed
Reading event.timeStamp again in the same handler returns the same number — it is not updated to “now”.
Immutable
4
✓
Subtract across events
Store last = event.timeStamp and compute deltas on the next event — the official profiling pattern.
Important
📝 Notes
Available since jQuery 1.2.6 — returns a Number (epoch milliseconds at event creation).
Measures time between event creation and January 1, 1970 — not current time inside the handler.
For wall clock now, use (new Date).getTime() or Date.now() — as stated in the official jQuery docs.
Official profiling pattern: read at two points and note the difference; consecutive clicks use event.timeStamp - last.
Firefox caveat — long-standing bug: timeStamp not populated correctly; exact event creation time unavailable there.
For in-handler duration, prefer performance.now() over re-reading event.timeStamp.
Read-only — store in a variable if you need the value after async work in the same dispatch.
Compatibility
Browser Support
event.timeStamp is a standard DOM Event property exposed on jQuery’s normalized event object since jQuery 1.2.6+. Chromium, Safari, and Edge populate it reliably for inter-event deltas. Firefox has a documented long-standing bug where the value is not set correctly — test timing logic accordingly.
✓ jQuery 1.2.6+ · DOM standard
jQuery event.timeStamp
Event creation epoch ms — subtract across events.
95%Wide support
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
timeStampNumber (ms)
Bottom line: Reliable in Chrome/Safari/Edge; verify Firefox separately.
Wrap Up
Conclusion
event.timeStamp tells you when the browser created the event — epoch milliseconds fixed for that dispatch. The official demo subtracts consecutive values to show time between clicks, and the same pattern powers throttling and double-click detection.
Reach for Date.getTime() or Date.now() when you need current wall clock time, and performance.now() for high-resolution work inside a handler. Remember the Firefox caveat before relying on precise creation times everywhere.
Subtract event.timeStamp - last for gaps between consecutive user events
Store last = event.timeStamp after each handled event in throttle/delta patterns
Use (new Date).getTime() when you need current wall-clock time in the handler
Use performance.now() to measure work duration inside one handler
Test timing features in Chrome, Safari, and Edge; plan Firefox fallbacks
❌ Don’t
Treat event.timeStamp as “now” — it is event birth time only
Re-read event.timeStamp expecting it to advance during long synchronous work
Assume Firefox provides accurate timeStamp values without verification
Confuse epoch timeStamp with monotonic performance.now() origins
Forget to reset stored last after double-click or throttle sequences end
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about event.timeStamp
Event birth time — subtract across events.
5
Core concepts
ms01
timeStamp
Event birth
API
#02
Number
Epoch ms
Type
−03
Delta
last diff
Demo
now04
Date
Wall clock
Compare
FF05
Firefox
Bug caveat
Note
❓ Frequently Asked Questions
event.timeStamp is a Number on the jQuery event object. It returns the number of milliseconds between when the browser created the event and January 1, 1970 (Unix epoch). Available since jQuery 1.2.6. It is the event creation time — not the current wall-clock time when your handler runs.
Store the previous event.timeStamp in a variable. On the next event, subtract: diff = event.timeStamp - last. The official jQuery demo appends the diff in milliseconds. Then update last = event.timeStamp for the next comparison.
No. event.timeStamp is fixed when the browser created the event. For current wall-clock time when your handler executes, use (new Date).getTime(), Date.now(), or performance.now() instead.
Bind click on a div. On first click append "Click again." On later clicks compute diff = event.timeStamp - last and append "time since last event: " + diff. Set last = event.timeStamp each time.
Firefox has a long-standing bug where event.timeStamp is not populated correctly. You cannot rely on it for exact event creation time in Firefox. Test profiling and throttle logic in Chrome, Safari, and Edge; add fallbacks or skip Firefox-specific timing if precision matters.
event.timeStamp is epoch milliseconds at event creation — comparable across two events via subtraction. performance.now() is a high-resolution monotonic clock from navigation start, ideal for measuring work inside one handler. Date.getTime() and Date.now() return current wall-clock epoch ms when you call them — not the event birth time.
Did you know?
The jQuery API has documented a Firefox bug with event.timeStamp for years — the property exists on the event object but is not populated correctly, so you cannot know the exact event creation time in Firefox. The official docs recommend (new Date).getTime() when you need current time inside a handler, which sidesteps confusion between event birth time and handler execution time.