I have DOM is like this:
<a href='javascript:void(0)' id='link1'>Element with events bound initially</a>
<a href='javascript:void(0)' id='link2'>Element to which events are bound in future</a>
And this javascript:
$(function(){
$('#link1').bind('click',function(){alert('do something to make me happy');})
});
Now some time in future i want to copy all events bound on link1 to link2. I am doing it as written below please suggest some better way if possible or available.
var _elmEvents = $(#link1).data('events');
if (_elmEvents) {
$.each(_elmEvents, function (event, handlers) {
$.each(handlers, function (j, handler) {
$('#link2').bind(event, handler);
});
});
}