Non-native DOM triggers, customized custom events.
- currentTarget (DOM object): The element node to trigger the event on.
- type (string): The type of event to trigger, e.g. "keydown".
- bubbles (boolean): Indicates whether the event should bubble.
- cancelable (boolean): Indicates whether the event can be canceled.
- detail (object): any value, stored in the detail property of the event object.
1 function customEvent (currentTarget, type, bubbles, cancelable, detail) { 2 /* custom response event */ 3 // IE9+ 4 if (document.implementation.hasFeature("CustomEvents", "3.0" )) { 5 bubbles = (bubbles === undefined) ? true : bubbles; // Default event bubbles 6 cancelable = (cancelable === undefined) ? true : cancelable; // Default event can be canceled7 detail = detail || {}; // Here can be the information and data contained in the event 8 var e = document.createEvent("CustomEvent"); 9 e.initCustomEvent(type, bubbles, cancelable, detail); 10 currentTarget.dispatchEvent(e); // Trigger event 11 } 12 else console.log("This environment does not support custom events!" ); 13 }