Created
December 4, 2015 16:37
-
-
Save wallacemaxters/098f2c0b8e3f8dc9e6a4 to your computer and use it in GitHub Desktop.
Simulate key press in element with jQuery
This file contains 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 ($){ | |
$.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