How can I copy events from one group to another?
Html (note that .view
has no event on purpose),
<div class="original">
<a href="#" class="edit">edit</a>
<a href="#" class="delete">delete</a>
<a href="#" class="view">view</a>
</div>
<div class="copy">
<a href="#" class="edit">edit</a>
<a href="#" class="delete">delete</a>
<a href="#" class="view">view</a>
</div>
jQuery:
var parent = $('.original');
$(".edit", parent).click(function(){
return false;
});
$(".delete", parent).click(function(){
return false;
});
$.each($._data($('.edit:first').get(0), 'events'), function() {
// iterate registered handler of original
$.each(this, function() {
$('.edit:last').bind(this.type, this.handler);
});
});
With this, I only manage to copy the event of .edit
to another, but I have a lot more events to copy to another group.
Any ideas?
EDIT:
$("a").each( function(i, e) {
var $each = this;
//console.log($._data($(this).get(0), 'events'));
if($._data($(this).get(0), 'events') !== undefined){
$.each($._data($($each).get(0), 'events'), function() {
$.each(this, function() {
$("." + $each.className, copy).unbind(this.type, this.handler).bind(this.type, this.handler);
});
});
}
});