emit event js code example
Example 1: javascript custom events with data
window.addEventListener("MyEventType", function(evt) {
alert(evt.detail);
}, false);
var evt = new CustomEvent("MyEventType", {detail: "Any Object Here"});
window.dispatchEvent(evt);
Example 2: trigger event javascript
document.querySelector(theElem).dispatchEvent(new Event('mouseover'))
Example 3: javascript emit event
const event = new Event('build');
elem.addEventListener('build', function (e) { }, false);
elem.dispatchEvent(event);