Home  >  Article  >  Web Front-end  >  jQuery determines whether an event is bound to an element_jquery

jQuery determines whether an event is bound to an element_jquery

WBOY
WBOYOriginal
2016-05-16 18:43:061008browse

After some research, I found that jQuery caches events. In fact, it is also to prevent memory overflow and speed up page unloading. It also includes multiple function triggers, convenient management, and many other benefits. You can refer to this article for details.
jQuery will unload all bound events and release memory during window.unload.

OK, let’s get down to business. To determine whether an event has been bound to an element, use the following statement

Copy the code The code is as follows:

jQuery .data(elem,"events")[type] //Old versions can also be used
$(elem).data("events")[type] //Can only be used after 1.2.3

Return value:
An Object, which can be traversed using for in. or undefined.
Parameters:
elem is a DOM object, type is the event type.
Example:
Determine whether the click event is bound to the element with id foo
Copy the code The code is as follows:

if( $("#foo").data("events")["click"] ){
//your code
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn