initEvent method (event)
9 | ||||
Initializes an event object created by the createEvent method.
Any type of event can be initialized with this method, but the type-specific initialization methods provide more possibilities for non-basic event types.
You can find the possible event types and initialization methods on the page for the createEvent method.
After initialization, the event can be dispatched with the dispatchEvent method.
After initialization, the event can be dispatched with the dispatchEvent method.
In Internet Explorer before version 9, use the createEventObject method to create a new event object and the fireEvent method to dispatch it.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the name (type) of the event to initialize.
This parameter is case sensitive! Sets the type property of the event object.
For a complete list of events, see the page for Events in JavaScript.
The initEvent method is appropriate for initialization of basic event types principally, for other events, use the type-specific initialization methods.
Note: custom event names are also allowed.
Events represented by the Event interface:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. Boolean that specifies whether the event can bubble or not. Sets the bubbles property of the event object.
One of the following values:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. Boolean that specifies whether the event can be canceled or not. Sets the cancelable property of the event object.
One of the following values:
|
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the initEvent method to dispatch a change event when the selection of a list control is modified by script:
|
||||
<head> <script type="text/javascript"> function Select () { var fruits = document.getElementById ("fruits"); if (fruits.selectedIndex == 0) { fruits.selectedIndex = 1; } else { fruits.selectedIndex = 0; } // Dispatch a change event if (document.createEvent) { // all browsers except IE before version 9 var changeEvent = document.createEvent ("Event"); changeEvent.initEvent ("change", true, false); fruits.dispatchEvent (changeEvent); } else { alert ("Your browser does not support the createEvent method!"); } } function OnChange () { alert ("The selected fruit is changed!"); } </script> </head> <body> <select id="fruits" onchange="OnChange ()"> <option value="Apple">Apple</option> <option value="Pear">Pear</option> <option value="Peach" selected="selected">Peach</option> </select> <button onclick="Select ()">Select another fruit!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
event
createEvent
initDragEvent
initKeyEvent
initMessageEvent
initMouseEvent
initMutationEvent
initOverflowEvent
initTextEvent
initUIEvent
createEvent
initDragEvent
initKeyEvent
initMessageEvent
initMouseEvent
initMutationEvent
initOverflowEvent
initTextEvent
initUIEvent
External links:
User Contributed Comments