Skip to content

Instantly share code, notes, and snippets.

@wallacemaxters
Created December 4, 2015 16:37
Show Gist options
  • Save wallacemaxters/098f2c0b8e3f8dc9e6a4 to your computer and use it in GitHub Desktop.
Save wallacemaxters/098f2c0b8e3f8dc9e6a4 to your computer and use it in GitHub Desktop.
Simulate key press in element with jQuery
(function ($){
$.fn.triggerKeyPress = function (keys)
{
var keydownEvent = $.Event("keydown");
var $self = this;
$.each(keys, function(index, value) {
var simulatedKey = $.extend({}, keydownEvent, {which: value, keyCode: value});
$self.trigger(simulatedKey);
});
}
)( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment