Right now i am wondering is this below is possible:
I have some element which has some event. Let's say for now that on element click i show alert('clicked)
;
And the question: is there is any way to grab events of this element and add this events to for example beyboard's left arrow button ?
What i'm looking for is: grab all events from one element and attch this events to another element - in this case it's keyborad button, but this may be for example another DOM element.
Thanks for advice / strategy / info if this is possible.
Edit: i'v found this code snippet, but this don't work, but address well waht i try to do:
function copyEvents(source, destination) {
// Get source events
var events = source.data('events');
// Iterate through all event types
$.each(events, function(eventType, eventArray) {
// Iterate through every bound handler
$.each(eventArray, function(index, event) {
// Take event namespaces into account
var eventToBind = event.namespace.length > 0
? (event.type + '.' + event.namespace)
: (event.type);
// Bind event
destination.bind(eventToBind, event.data, event.handler);
});
});
}
var oldE = $('.old');
var newE = $('.new');
copyEvents(oldE, newE);
I'm getting this error from jquery.js: jquery.2.0.js:4 Uncaught TypeError: Cannot read property 'length' of undefined