Test if event handler is bound to an element in jQuery?

You can get this information from the data cache log them to the console (firebug, ie8) console. Dir( $('#someElementId'). Data('events') ) or iterate them jQuery.

Each($('#someElementId'). Data('events'), function(i, event){ jQuery. Each(event, function(i, handler){ console.

Log( handler.toString() ); }); }) Another way is you can use the following bookmarklet but obviously this does not help at runtime.

You can get this information from the data cache. //log them to the console (firebug, ie8) console. Dir( $('#someElementId').

Data('events') ); //or iterate them jQuery. Each($('#someElementId'). Data('events'), function(i, event){ jQuery.

Each(event, function(i, handler){ console. Log( handler.toString() ); }); }); Another way is you can use the following bookmarklet but obviously this does not help at runtime.

– Russ Cam Aug 5 '09 at 22:27 2 Yes Russ, that I true. But inline handlers are grim and deserve not to be shown! – redsquare Aug 5 '09 at 22:28 It worked!

At least it works with events assigned with jQuery. I haven't tested it with events assigned otherwise. Thank you.

– mikez302 Aug 5 '09 at 22:41.

I wrote a plugin called hasEventListener which exactly does that : github.com/sebastien-p/jquery.hasEventLi... Hope this helps.

1 This plugin should be the accepted answer for anyone who is using jQuery. – free-dom Jan 11 at 22:29 Hopefully I can save someone else some time. HasEventListener doesn't work for live bound events.(v1.0.5) – SooDesuNe Feb 3 at 21:27 My hasEventListener plugin will be updated this week with now a full support for live and delegated events.

– Sebastien P. Feb 22 at 22:41.

I don't think that the hasEventListener plugin mentioned will handle custom events e.g. Var obj = {id:'test'}; $(obj). Bind('custom', function(){ alert('custom'); }). Trigger('custom'); alert($(obj).

HasEventListener('custom')); Also, at least in jQuery 1.5 I think you need to be careful using $(target). Data('events') because it returns differently for events that have been bound to objects as above. You need to do something like: var events = $(target).

Data("events"); if(typeof events === "function"){ events = events. Events; } I am using this sort of approach and it works but it feels a bit like I am at the mercy of jquery internals and that really I shouldn't be doing it!

Killing off the binding when it does not exist yet is not the best solution but seems effective enough! The second time you ‘click’ you can know with certainty that it will not create a duplicate binding. I therefore use die() or unbind() like this: $("#someid").

Die("click"). Live("click",function(){... or $("#someid"). Unbind("click").

Bind("click",function(){...

That helped me! Thanks :) – Nima Aug 14 at 19:05.

I don't think that the hasEventListener plugin mentioned will handle custom events e.g. Also, at least in jQuery 1.5 I think you need to be careful using $(target). Data('events') because it returns differently for events that have been bound to objects as above. I am using this sort of approach and it works but it feels a bit like I am at the mercy of jquery internals and that really I shouldn't be doing it!

You can get this information from the data cache.

That helped me! Thanks :) – Nima Aug 14 at 19:05 +1 very neat even though it doesn't answer the question. – Noel Abrahams Nov 23 at 20:41.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions