Last active
October 10, 2016 17:32
-
-
Save bitsmanent/c7d9d972f4ffc02e2806efb7466c5475 to your computer and use it in GitHub Desktop.
Trig a JavaScript event
This file contains hidden or 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
| 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