4

I have a simple input element :

  <input class="a" />     // <---notice - no inline onclick function

someone is doing

$(".a").on('click',function () {alert('1')});
// ...and later
$(".a").on('click',function () {alert('2')});

Now , I want to find : "which functions are executed when clicking the element" ?

How can I do it in Jquery/Javascript?

p.s. please ignore the anonymous functions here , I could also attach a regular named function .

jsbin

(im using ( as jsbin shows , with 1.8.3 - the latest))

Community
  • 1
  • 1
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
  • 1
    http://stackoverflow.com/questions/2223777/jquery-can-i-get-a-reference-to-the-bound-events-on-an-element – eliah Dec 19 '12 at 16:56
  • Be careful with that: since events bubble, the event's handler might not be the event's target. – zneak Dec 19 '12 at 16:56
  • possible duplicate of [Querying the list of event listeners registered for a given event type](http://stackoverflow.com/questions/3157969/querying-the-list-of-event-listeners-registered-for-a-given-event-type) – zneak Dec 19 '12 at 16:58
  • @eliah it is not working. 9the solutions there). http://jsbin.com/apageb/3/edit – Royi Namir Dec 19 '12 at 17:00
  • **it is not duplicate since its been removed in the latest version of jQuery** – Royi Namir Dec 19 '12 at 17:01
  • @ToniToniChopper i didnt talk about the console. The answers on the duplicate doesnt work.( in jquery 1.8.3( – Royi Namir Dec 19 '12 at 17:03

2 Answers2

3

Try this:

console.log($._data( $(".a")[0], "events" ));

Tested in 1.8.2

Esailija
  • 138,174
  • 23
  • 272
  • 326
1

There is a way to do it with the current and older versions of jQuery, however it is internal and depreciated and will be going away soon.

console.log($(".a").data("events"));
Kevin B
  • 94,570
  • 16
  • 163
  • 180
  • Ah, it has already been removed in the latest version of jQuery. The last version it worked in was 1.7.2. – Kevin B Dec 19 '12 at 16:59