tags:

views:

47

answers:

3

I have some elements and I'm using some jQuery plugins. I want to see if the elements are already bound to events.

+4  A: 

Using firebug:

console.log( jQuery(someElements).data('events') );

Note that this will only return events bound by jQuery's event mechanism.

The returned object will be in the following format (note this is assuming 1.4):

{
    eventName /* e.g. "click" */: [/* handler array */
        {
            /* handler object */
            data: /* data passed to handler */,
            guid: /* guid, for internal use */,
            namespace: /* for namespaced events */,
            type: /* event name, e.g. "click" */,
            handler: /* actual handler function */
        }
    ]
}
J-P
+2  A: 

If firefox/firebug is your js debugging environment you can add http://www.softwareishard.com/blog/firebug/eventbug-alpha-released/ to firebug

Unreason
A: 

Here's another note: jQuery lets you bind events with a 2-dimensional namespace. If you want to be able to bind and unbind your event handlers without disturbing other stuff, you can use a dotted-pair notation to give your own "click" handler an identity that'll let you later unbind it without screwing up unrelated code:

 $('#something').bind('click.myClick', function() { ... });

then later:

 $('#something').unbind('click.myClick');
Pointy