javascript - move event handler with jQuery -


i have issue driving me crazy , last resort placing question here.

i want move onclick event element onfocus event of same element , using following code:

$("#theelement").bind("focus", {}, $("#theelement").data("events").click); $("#theelement").unbind("click"); 

maybe have guess it. not work.

how make work? getting "fn.apply not function" message in following piece of code jquery 1.3.2:

proxy: function( fn, proxy ){         proxy = proxy || function(){ return fn.apply(this, arguments); };         // set guid of unique handler same of original handler, can removed         proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++;         // proxy can declared argument         return proxy;     } 

edit: i'm sorry, should have mentioned. comes plugin stuff when clicking element. want make same thing when element gets focus not when cliked simplest solution thought off since can't modify code plugin.

edit: found problem. similar @sje397 posted in answer, not

$('#theelement').data('events').click[0] 

but

$('#theelement').data('events').click[3] 

for reason, if 1 event registered thing ends 3 (the guid in piece of code jquery).

i suggest naming event handler in first place, like

$('#theelement').click(function myhandler() {   //... }); 

then, can do

$("#theelement").bind("focus", {}, myhandler); $("#theelement").unbind("click"); 

this should make more readable, fixing bug.

if can't, can do:

// assuming yours first handler var myhandler = $('#theelement').data('events').click[0];   $("#theelement").bind("focus", {}, myhandler); $("#theelement").unbind("click"); 

also not in jquery 1.4.3+, key changed __events__. see this answer.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -