The initEvent() method initializes an event created with document.createEvent() by setting type, bubbles, and cancelable before dispatchEvent(). Learn the old pattern, why it is deprecated, and how to migrate to new Event()—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
undefined
03
Args
type, bubbles, cancelable
04
Pairs with
createEvent
05
Modern
new Event()
06
Status
Deprecated
Fundamentals
Introduction
Years ago, creating a synthetic event often meant two steps: document.createEvent("Event"), then event.initEvent(type, bubbles, cancelable), then dispatchEvent.
Today you write one expression: new Event("click", { bubbles: true, cancelable: false }). Same idea—name, bubble flag, cancel flag—cleaner API. This tutorial shows the old method so you can recognize it in legacy codebases and replace it confidently.
💡
Beginner tip
Call initEvent()beforedispatchEvent(). After dispatch, MDN notes that calling it again does not re-initialize the dispatched event in a useful way.
Concept
Understanding Event.initEvent()
An instance method that sets the core flags on an event created with Document.createEvent().
type — string event name (for example "click").
bubbles — whether the event bubbles; sets event.bubbles.
cancelable — whether preventDefault() can cancel it; sets event.cancelable.
Return value — none (undefined).
Status — Deprecated on MDN; available in Web Workers, but avoid for new code.
Event.initEvent() is marked Deprecated on MDN. Many browsers still implement it for compatibility with old pages, but you should not rely on it for new work. Logos use the shared browser-image-sprite.png sprite from this project. Prefer new Event().
✓ Deprecated · Prefer Event()
Event.initEvent()
Legacy initializer for createEvent events. Use Event() (or a more specific constructor) instead.
LegacyDeprecated API
Google ChromeStill present for legacy pages; prefer constructors
Legacy
Mozilla FirefoxStill present for legacy pages; prefer constructors
Legacy
Apple SafariStill present for legacy pages; prefer constructors
Legacy
Microsoft EdgeStill present for legacy pages; prefer constructors
Legacy
OperaStill present for legacy pages; prefer constructors
Legacy
Internet ExplorerHistorically used createEvent / initEvent heavily
Legacy
Event.initEvent()Avoid in new code
Bottom line: Recognize initEvent in old code, then migrate to new Event(type, { bubbles, cancelable }).
Wrap Up
Conclusion
Event.initEvent() is a deprecated way to set type, bubbles, and cancelable on events from createEvent. Learn it to read old code; ship new features with new Event() (or a more specific constructor).
Map (type, bubbles, cancelable) to constructor options
Feature-detect only if you must support ancient browsers
Document migrations when removing initEvent
Use this page to understand legacy snippets
❌ Don’t
Write new production code with initEvent
Rely on re-calling it after dispatchEvent
Mix createEvent and constructor styles in one helper
Forget that constructors can set more options (e.g. composed)
Teach beginners initEvent as the default pattern
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about initEvent()
Legacy initializer—migrate to constructors.
5
Core concepts
⚠️01
Deprecated
MDN status
Status
🔧02
3 args
type / bubbles / cancelable
API
📝03
createEvent
legacy partner
Pair
✓04
Event()
modern replace
Prefer
🚀05
dispatch
after init
Flow
❓ Frequently Asked Questions
It initializes an event created with document.createEvent() by setting type, bubbles, and cancelable before you call dispatchEvent(). Once the event has been dispatched, calling initEvent() again does nothing useful.
Yes. MDN marks Event.initEvent() as Deprecated. Prefer event constructors such as new Event("click", { bubbles: true, cancelable: false }).
Use new Event(type, options), or a more specific constructor (CustomEvent, MouseEvent, KeyboardEvent, and so on). Then dispatch with target.dispatchEvent(event).
Modern code should not need initEvent() at all. The constructor options already set type, bubbles, and cancelable. initEvent() was paired with the older document.createEvent() API.
type (string event name), bubbles (boolean), and cancelable (boolean). After init, you can read event.type, event.bubbles, and event.cancelable.
Yes. MDN notes the feature is available in Web Workers, but it remains deprecated—prefer constructors there too when available.
Did you know?
Modern constructors can set flags initEvent never covered, such as composed for Shadow DOM. That is another reason to prefer new Event("notify", { bubbles: true, composed: true }) over the old two-step API.