Skip to content

Instantly share code, notes, and snippets.

@Hampei
Last active October 13, 2015 07:27
Show Gist options
  • Save Hampei/4160154 to your computer and use it in GitHub Desktop.
Save Hampei/4160154 to your computer and use it in GitHub Desktop.
copy delegated jquery events from one element to another
function copy_jquery_on_event_handlers(source, target) {
$.each(['click', 'submit', 'ajax:beforeSend', 'ajax:complete'], function(i, event_type) {
$.each($._data(source, 'events')['click'], function(j, jqe_spec) {
if (jqe_spec.selector != undefined)
$(target).on(event_type, jqe_spec.selector, jqe_spec.handler);
});
});
}
copy_jquery_on_event_handlers(body, new_bubble_element);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment