Home > Web Front-end > JS Tutorial > How can jquery determine whether an element is bound to an event?

How can jquery determine whether an element is bound to an event?

coldplay.xixi
Release: 2020-11-17 10:36:49
Original
1899 people have browsed it

Jquery method to determine whether an element is bound to an event: 1. The old version of the judgment statement [jQuery.data(elem, "events") [type]]; 2. [1.2.3] version can only be used after [$(elem).data("events")[type]].

How can jquery determine whether an element is bound to an event?

Recommended: "jquery video tutorial"

Jquery method to determine whether an element is bound to an event:

To determine whether an event has been bound to an element, use the following statement

jQuery.data(elem,"events")[type] //老版本也能用
Copy after login
$(elem).data("events")[type] //1.2.3以后才能用
Copy after login

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

if( $("#foo").data("events")["click"] ){ 
    //your code 
}
Copy after login

Related Free learning recommendations: JavaScript (video)

The above is the detailed content of How can jquery determine whether an element is bound to an event?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template