Last active
May 11, 2020 20:20
-
-
Save LucasCalazans/f0a642913be2bba57dfe602344f3e07d to your computer and use it in GitHub Desktop.
Trigger function without jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const trigger = (element, eventName) => { | |
let event; | |
if (document.createEvent) { | |
event = document.createEvent("HTMLEvents"); | |
event.initEvent(eventName, true, true); | |
} else { | |
event = document.createEventObject(); | |
event.eventType = eventName; | |
} | |
event.eventName = eventName; | |
(document.createEvent) ? | |
element.dispatchEvent(event) : | |
element.fireEvent("on" + event.eventType, event); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment