Skip to content

Instantly share code, notes, and snippets.

@mtranter
Created August 25, 2014 14:52
Show Gist options
  • Save mtranter/6c418fc60f95bb993ebe to your computer and use it in GitHub Desktop.
Save mtranter/6c418fc60f95bb993ebe to your computer and use it in GitHub Desktop.
Copy jQuery bound events between elements
(function($, undefined){
function copyEvents(source, target) {
var evs = $._data(source[0], 'events');
for (var ev in evs) {
for (var i = 0; i < evs[ev].length; i++)
$.fn[ev].apply(target, [evs[ev][i].handler]);
}
}
$.fn.copyEventsFrom = function(src){
copyEvents(src, this);
}
$.fn.copyEventsTo = function(target){
copyEvents(this, target);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment