admin管理员组

文章数量:1278918

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??

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??

Share Improve this question asked May 4, 2012 at 14:01 FairyQueenFairyQueen 2,3738 gold badges38 silver badges58 bronze badges 3
  • stackoverflow./questions/2382994/… – Florian Margaine Commented May 4, 2012 at 14:03
  • duplicate? -> stackoverflow./questions/1515069/… – rt2800 Commented May 4, 2012 at 14:03
  • Duplicate Question......stackoverflow./questions/2382994/… – Pyare Commented Feb 8, 2014 at 11:53
Add a ment  | 

3 Answers 3

Reset to default 6

This should get you a list of events:

jQuery(theElement).data('events');

You could try this:

$("element").data("events");

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");
}

本文标签: jqueryIs there a way in javascript to detect if an element has any events attached to itStack Overflow