Skip to content

Instantly share code, notes, and snippets.

@sinpaout
Created July 11, 2016 07:38
Show Gist options
  • Save sinpaout/acbf971076de7ab1bdd93616313d13ce to your computer and use it in GitHub Desktop.
Save sinpaout/acbf971076de7ab1bdd93616313d13ce to your computer and use it in GitHub Desktop.
dispatch Enter key's keypress event.
// for detail http://stackoverflow.com/questions/8942678/keyboardevent-in-chrome-keycode-is-0/12522752#12522752
var ev = document.createEvent('Events');
ev.initEvent('keypress', true, true);
ev.keyCode = 13;
ev.which = 13;
ev.charCode = 13;
ev.key = 'Enter';
ev.code = 'Enter';
document.querySelector('.new-todo').dispatchEvent(ev);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment