Skip to content

Instantly share code, notes, and snippets.

@adamdehaven
Last active December 13, 2018 15:22
Show Gist options
  • Select an option

  • Save adamdehaven/95554569d39b86af23793c1bc3ac254f to your computer and use it in GitHub Desktop.

Select an option

Save adamdehaven/95554569d39b86af23793c1bc3ac254f to your computer and use it in GitHub Desktop.
jQuery Paste Events
$.fn.pasteEvents = function( delay ) {
if (delay == undefined) delay = 20;
return $(this).each(function() {
var $el = $(this);
$el.on('paste', function() {
$el.trigger('prepaste');
setTimeout(function() { $el.trigger('postpaste'); }, delay);
});
});
};
$('#some-element').on('prepaste', function () {
// do something
}).on('postpaste', function () {
// do something
}).pasteEvents();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment