--- title: Event.initEvent() slug: Web/API/Event/initEvent translation_of: Web/API/Event/initEvent ---
The Event.initEvent()
method is used to initialize the value of an {{ domxref("event") }} created using {{ domxref("Document.createEvent()") }}.
Events initialized in this way must have been created with the {{ domxref("Document.createEvent()") }} method. This method must be called to set the event before it is dispatched, using {{ domxref("EventTarget.dispatchEvent()") }}. Once dispatched, it doesn't do anything anymore.
Не используйте этот метод, т.к. он устаревший. (deprecated)
Вместо него используйте такой специальный конструктор событий, как {{domxref("Event.Event", "Event()")}}. Страница Creating and triggering events даст больше информации о возможностях использования.
event.initEvent(type, bubbles, cancelable);
type
bubbles
cancelable
// Create the event. var event = document.createEvent('Event');
// Create a click event that bubbles up and // cannot be canceledevent.initEvent('click', true, false); // Listen for the event. elem.addEventListener('click', function (e) { // e.target matches elem }, false); elem.dispatchEvent(event);
Спецификация | Статус | Комментарий |
---|---|---|
{{SpecName('DOM WHATWG', '#dom-event-initevent','Event.initEvent()')}} | {{Spec2("DOM WHATWG")}} | Начиная с {{SpecName('DOM2 Events')}} - deprecated, заменено на event constructors. |
{{SpecName('DOM2 Events','##Events-Event-initEvent','Event.initEvent()')}} | {{Spec2('DOM2 Events')}} | Начальное определение. |
{{Compat("api.Event.initEvent")}}