Return to Snippet

Revision: 56955
at April 26, 2012 22:02 by chlab


Initial Code
// iterate event types of original
$.each($('#original').data('events'), function() {
  // iterate registered handler of original
  $.each(this, function() {
    $('#target').bind(this.type, this.handler);
  });
});

Initial URL
http://www.chlab.ch

Initial Description
Here's a snippet for copying (all) the eventhandlers of one element to another with jQuery and effectively cloning the behavior of one element.

Keep in mind that if it's possible, you should just register the same handlers you actually need, instead of just blindly copying all of them. But in some cases, e.g. when using a plugin that you do not wish to modify, this can come in handy.

Initial Title
Copy one element\'s eventhandlers to another

Initial Tags
event, jquery, copy

Initial Language
jQuery