Is there a built-in way to create custom events in JavaScript natively?

I played with JavaScript a while ago, and it annoyed me that I could not create my own event.

I saw the Framework with this built-in (jQuery, MooTools, Prototype. Dojo is not weird because it seems to do everything and your laundry), and I actually created my own system to create and trigger custom events.

It just seems like there should be a way of doing it. Does anyone know how to do this / if you can even?

+2
source share
1 answer
var dragEvent = document.createEvent("Event");
dragEvent.initEvent("dragged", true, true);
el.dispatchEvent(dragEvent);

. DOM Level 2 Events. . createEvent(), initEvent()/initMouseEvent()/initUIEvent() dispatchEvent() MDC.

.

+7

All Articles