0

for example I have:

<a href="" id="#activador">asdasd</a>
...
//js code in other place or other file hard to find, I have this:
$('#activador').click(simplefunction);       or
$(document).on('click','#activador',simplefunction);     or
$('#activador').live('click',simplefunction);

function simplefunction(){
alert('hello');
}
...

How can I find if the html ('#activador') have a function attached, and how can I find what function the element ('#activador') will trigger?

I know using

var clickEvents = $('#activador').data("events").click;

but I cannot use something like this:

var clickEvents = $('#activador').data("events").on; or 
var clickEvents = $('#activador').data("events").live;
Antony
  • 14,900
  • 10
  • 46
  • 74
dexter00x
  • 879
  • 2
  • 14
  • 25
  • Actually, I'm not sure what's being asked here since `.click` will give you the function even if you use `on`. – gdoron Jun 04 '13 at 03:51
  • does not appears, when is .on('click','#activador',simplefunction); and I use: clickEvents = $('#activador').data("events").click; appear Cannot read property 'click' of undefined on chrome thanks – dexter00x Jun 04 '13 at 04:11

1 Answers1

1

You can use _data function to find out event associated with that element,

console.log($._data($('#activador'), "events").click);
  • thanks, I have put that code but appears: Uncaught TypeError: Cannot read property 'click' of undefined (anonymous function) only can I get the functions attached when I use: $('#activador').click(simplefunction); and var clickEvents = $('#activator').data("events").click; but with 'on' or live appears the same error – dexter00x Jun 04 '13 at 04:10
  • @dexter00x which version of jQuery are you using? – The Mechanic Jun 04 '13 at 04:11
  • 1.7.1, do you think that should to use the latest version to do work that? – dexter00x Jun 04 '13 at 04:19
  • I have test with 1.10.1 but the same, using console.log($._data($('#activador')[0], "events").click); works only with: $('#activador').click(simplefunction); but not with: $(document).on('click','#activador',simplefunction); or $('#activador').live('click',simplefunction); – dexter00x Jun 04 '13 at 04:23
  • live function is actually deprecated in jQuery use bind instead –  Jun 04 '13 at 04:57
  • ok thanks, now still I cannot get the functions attached with 'on' please, – dexter00x Jun 04 '13 at 05:18
  • This is might what you want, $._data( $("#activador")[0], "events" ) –  Jun 05 '13 at 06:45