Skip to content

Instantly share code, notes, and snippets.

@LucasCalazans
Last active May 11, 2020 20:20
Show Gist options
  • Save LucasCalazans/f0a642913be2bba57dfe602344f3e07d to your computer and use it in GitHub Desktop.
Save LucasCalazans/f0a642913be2bba57dfe602344f3e07d to your computer and use it in GitHub Desktop.
Trigger function without jQuery
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