Skip to content

Instantly share code, notes, and snippets.

@bitsmanent
Last active October 10, 2016 17:32
Show Gist options
  • Select an option

  • Save bitsmanent/c7d9d972f4ffc02e2806efb7466c5475 to your computer and use it in GitHub Desktop.

Select an option

Save bitsmanent/c7d9d972f4ffc02e2806efb7466c5475 to your computer and use it in GitHub Desktop.
Trig a JavaScript event
function trigger(elems, evnm, data) {
var ev, i, len;
if(typeof elems == 'object' && elems.length == undefined)
elems = [elems];
len = elems.length;
if(!len)
return;
ev = new CustomEvent(evnm, {detail:data});
for(i = 0; i < len; ++i)
elems[i].dispatchEvent(ev);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment