Reputation: 2373
I have a list of links on the page and sometimes they have events attached to them and sometimes not (they just don't do anything). I want to say, 'if this element has no event handlers (basically it doesn't do anything), then add a class of disabled to it. I googled it but didn't find anything for detecting event handlers. Does anyone know of a way to do something like this??
Upvotes: 4
Views: 2245
Reputation: 21
I use the following, tested in IE, FF and Chrome:
if(typeof document.getElementById("elementname").onchange === "function"){
alert("has a function");
} else {
alert("no function");
}
Upvotes: 2
Reputation: 10303
This should get you a list of events:
jQuery(theElement).data('events');
Upvotes: 6