Home  >  Article  >  Web Front-end  >  How to determine whether an element is bound to an event in jquery

How to determine whether an element is bound to an event in jquery

王林
王林Original
2020-11-25 13:47:452304browse

Jquery method to determine whether an element is bound to an event: [$(elem).data("events")[type]]. The parameter elem is a DOM object, and the parameter type represents the event type.

How to determine whether an element is bound to an event in jquery

Environment:

This article applies to all brands of computers.

(Learning video sharing: jquery video tutorial)

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

jQuery.data(elem,"events")[type] //老版本也能用 
$(elem).data("events")[type] //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

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

Related recommendations: js tutorial

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

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