Created
August 25, 2014 14:52
-
-
Save mtranter/6c418fc60f95bb993ebe to your computer and use it in GitHub Desktop.
Copy jQuery bound events between elements
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($, 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