How to prevent double triggering of events in jquery?

This article deals with the following queries:

".toggle() getting called twice on single click", "How to remove event if the same event handler already exists in jQuery", "How to prevent duplicate events in jquery", "How to prevent double triggering of events in jquery"

If you encounter a situation where previously assigned events are triggered together with new events, it is a reasonable solution to delete all previously applied events of the same type and assign a new one. By resetting all previous assignments each time.

Use this simple one line for remove previous all events for selector:

jQuery( '.your-selector' ).off("click");//this line will remove all similar events related to click previously defined for this selector
jQuery( '.your-selector' ).click( function (e) { 
your code
})

Метаданные статьи

Идентификатор статьи:
137
Категория:
Дата добавления:
15.12.2024 21:06:31
Просмотры:
11
Рейтинг (Голоса):
(0)

Связанные статьи