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
3 Answers
Reset to default 6This 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");
}
版权声明:本文标题:jquery - Is there a way in javascript to detect if an element has any events attached to it? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741273250a2369583.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论