What Is InitEvents() And Should I Use It In 2018?
I'm trying to understand the code of another programmer and there is a initEvents () method. Some articles tells that this is an outdated method, but I'm not sure. Could you help m
Solution 1:
This is indeed a deprecated method which will init the event before dispatching
, you should instead use the Event constructor which have a second argument for event initialisation and then dispatch the event as you like.
Something like this:
// create a look event that bubbles up and cannot be canceled
var evt = new Event("look", {"bubbles":true, "cancelable":false});
document.dispatchEvent(evt);
// event can be dispatched from any element, not only the document
myDiv.dispatchEvent(evt);
Post a Comment for "What Is InitEvents() And Should I Use It In 2018?"