jQuery determines whether a method of the specified event is bound to the element

  • 2020-05-16 06:24:41
  • OfStack

This article demonstrates how jQuery determines whether a specified event is bound to an element. Share with you for your reference. The details are as follows:

For example, the following code can determine whether the element id=testdiv is bound to the click event, which is only valid for the jQuery bound event, and not for the normal JS event binding.


//jQuery event Encapsulation supports the ability to determine whether an event is bound to an element. This method applies only to jQuery Bound events 
var $events = $("#testdiv").data("events");
if( $events && $events["click"] ){
  //your code here
}

I hope this article is helpful for you to design jQuery program.


Related articles: