What happens if I bind a jQuery event that is already connected?

Now I spend a lot of time developing, trying to make sure that each event is connected only once. If I stop wasting time on this and several times associate the same function with the same event, what will happen? Will jQuery recheck the event (and therefore the waste processing time), or will it ignore it?

+3
source share
1 answer

From https://api.jquery.com/bind/

“Starting with jQuery 1.4.2, duplicate event handlers can be bound to an element rather than being discarded. This is useful when using the event data function or when other unique data is in closure around the event handler function.”

But then you should also try the following: It is better to use the .on () event handler, because you can do all your binding only once, and even before the subject you are binding exists. Easier to track all event handlers.

https://api.jquery.com/on/

0
source

All Articles