0

How can I get the computed click events from an HTML object in JavaScript. I need to call the functions that execute when I click an HTML object. Something like the following but getting the function calls directly

$("#htmlobject").click();
Felipe Barnett
  • 407
  • 4
  • 10

2 Answers2

3

Your question is fairly poorly written to explain what you're looking for.

I'm guessing its this: "There are event handlers that 'someone' has put on an element, I would like to know what they are, and optionally be able to trigger them manually". That said, the answer is "no, unless you bound the event callback its not yours to mess around with".

Other Reasons/Stuffs:

  1. You can't be sure if all the events were added using jQuery, even if they were newer versions of jQuery store the events in a non externally accessible way.
  2. You can't be sure if the event is on a child that bubbles, or on a parent that this will bubble to, etc... this would insanely complicate things.
  3. Elements do have a bunch of attributes you can access for read and write like "onclick" but this only returns anything if it was defined that way in the element, it does not return things added via .addEventListener or via frameworks.
  4. jQuery often abstracts things and adds them higher up, especially when done with live/on.. it will often actually subscribe to the parent element and let the events bubble up, then kinda "re-working" them so they appear to have been thrown by the "target"

Really though, even though you didn't write the page, if you have access to its source you can see what is being bound and where, you can see if they are using named callbacks or anonymous callbacks.

If the page is visible in the browser you can find it all, and as such I wonder what you mean by "I didn't make the page"

Nick Sharp
  • 1,881
  • 12
  • 16
0

Also these documentations can be useful: http://jquery.com/upgrade-guide/1.9/#data-events- http://api.jquery.com/jQuery.data/#jQuery-data-element-key

Ekin
  • 1,957
  • 2
  • 31
  • 45