views:

534

answers:

1

I am working on a greasemonkey script for gmail where i need to make a copy of the "Inbox" link. Using cloneNode works ok, but i think there's an onclick event that gets attached to it at runtime. So, this is a two part question: 1. Is there a way to see what events are attached to a node? 2. Is there a way to copy those events as well? The closest thing i found was jQuery, and i am not ready to go there yet. Thanks!

+3  A: 
  1. Not unless it's set using the onclick attribute on the element.
  2. Not reliably (you can copy the onclick attribute, but whether that will continue to work depends on if it was used and what it does).

You're better off adding your own click handler, and then triggering that event on the original... Or simulating the behavior in some other way.

Shog9
I considered simulating the click event as well, but i can't find a reliable way of doing that either.
Pasha
https://developer.mozilla.org/en/DOM/element.dispatchEvent
Shog9
That's what i was looking for! I can just dispatch the click even on the original node. Thank you very much!
Pasha