You can use jQuery._data
to check for events. The first argument should be a reference to the HTML element, not the jQuery object.
var ev = $._data(element, 'events');
if(ev && ev.click) alert('click bound');
Sample below.
$(function(){
$('#test').click(function(){
// NOTE: this below is refering to the HTML element, NOT the jQuery element
var ev = $._data(this, 'events');
if(ev && ev.click) alert('click bound to this button');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<button id="test">Click me to check for click handlers</button>
Also note that this method for checking events will only work when the event is bound via jQuery. If the event is bound via element.attachEventListener
, element.onclick
, <a onclick="doStuff()">
or any other non jQuery way, this will not work. If you're fitting into this boat, check this answer.