Manish Chandra Kumar
Manish Chandra Kumar

Reputation: 51

Event Verification After Attaching using "on"

I have attached an event using "on" later I want to verify that does the control contain this event.

Example:

//adding an event
$("#divControls").on('change',".myclass input", myfunction());

//verifying the event

if($(".myclass input"].change)
{
   // logic
}

How can I do that?

Upvotes: 0

Views: 29

Answers (3)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can try by iterating events bound for that element.

 jQuery.each($('#divControls').data('events'), function(i, event){

    jQuery.each(event, function(i, handler){

        console.log( handler.toString() );

    });

});

Upvotes: 0

A. Wolff
A. Wolff

Reputation: 74420

as it is delegated event, you just need to check for parents:

var $inputWithBoundChange = $(".myclass input").filter(function(){return $(this).closest('"#divControls"').length})

This will return all input inside .myclass element which have delegated event already bound.

Upvotes: 1

Manish Jangir
Manish Jangir

Reputation: 5437

Try this one

 $(document).on('change',"#divControls .myclass input", myfunction);

Upvotes: 0

Related Questions