M Miller
M Miller

Reputation: 5652

Is it possible to return the event function in jQuery?

Does anyone know if you can return a function for an event in jQuery? For example:

$(e).bind('ev', function(){
 alert('Hello world!');
});

$(e).getEvent('ev'); // returns function(){alert('Hello world!');};

I don't even know if returning a function is possible in JavaScript at all. Just curious.

Thanks.

Upvotes: 0

Views: 71

Answers (1)

alex
alex

Reputation: 490433

You can use data()...

$(e).data('events');

jsFiddle.

Or more specifically, in your case...

$(e).data('events').click[0].handler.toString();

jsFiddle.

Upvotes: 2

Related Questions