Reputation: 37058
Given an element, is there any way to tell with Javascript/jQuery whether there are any click events on that element?
I mean ANY click events. If clicking it would cause ANY code to execute, I want to know about it.
Is this possible?
It must be, if Firebug and Chrome Dev Tools can see all the event listeners tied to an object...
Upvotes: 0
Views: 95
Reputation: 3095
See http://jsfiddle.net/jvcDV/
HTML:
<a id="p1">I am link 1</a>
<a onclick="javascript:alert('hi');">I am link 2</a>
<a>I am link 3</a>
<a>I am link 4</a>
JS:
$(document).ready(function()
{
// Add inline event to a link element
document.getElementById('p1').onclick = function() { alert('hi'); };
$('a').each(function()
{
if(this.onclick == null)
{
alert("Link " + this.innerText + " does not have a onclick event");
}
else
{
alert("Link " + this.innerText + " does have a onclick event");
}
});
});
Upvotes: 0
Reputation: 3453
To get the list of events attached to particular element jquery uses
$._data( $("#yourelement")[0], "events" );
Upvotes: 1
Reputation: 1
There is a script called VisualEvent that does just the work you want. You can look at its code and see what goes on there.
Upvotes: 0