7

I need a hasEvents() method like

var someBool = hasEvents($("#myelement"));

that returns true if there are some bound events to any of the element's event handlers.

1 Answer 1

9

have you taken a look at the hasEvent() plugin? the code is pretty small:

(function(A) {
    A.fn.hasEvent = function(C) {
       var B = this.data("events");
       return( B && B[C] )
    }
}) (jQuery)

for your specific purpose you could modify it slightly:

(function($) {
    $.fn.hasEvents = function() {
        return new Boolean(this.data('events') );
    }
}) (jQuery);

$('#someDiv').click(function() {
    alert('new event');
});

$('#someDiv').hasEvents();      // true
$('#someOtherDiv').hasEvents(); // false
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.