Creates a DOM event of the specified type. This method is deprecated; use event constructors (CustomEvent) instead.
Method of dom/Documentdom/Document
Syntaxvar event = document.createEvent(eventType);
Parameters eventType
One of the following values. Case is not important.
Return ValueReturns an object of type DOM NodeDOM Node
The created event.
ExamplesThe following example demonstrates how to create and dispatch a custom event that bubbles and cannot be canceled.
var evt = document.createEvent("Event");
evt.initEvent("custom", true, false);
document.getElementById('target').dispatchEvent(evt);
To respond to the custom event created previously, the following example adds an event handler that interacts with the event by setting a expando property named detail
.
function reportEvent(evt) {
evt.detail = "Success.";
}
var p = document.getElementById('target');
p.addEventListener("custom", reportEvent, false);
Notes
If the event object is to be dispatched with dispatchEvent, the appropriate event initialization method must be called. For example, after creating an event of type UIEvent, call initUIEvent to initialize the event object’s values. **Security Warning: **For security reasons, events generated with createEvent are untrusted and have a isTrusted value of false.
Related specificationsMicrosoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4